Skip to main content

DB - Flashback Drop



Apos um drop table (excepto se foi usado purge), Oracle move a tabela para o recyclebin, neste post partilho como recuperar uma tabela depois de um  drop table, - e possivel tambem consultar o contedudo de tabelas no recycle bin.

As '/ as sysdba',

SQL> alter user hr identified by hr account unlock;
User altered.

SQL> conn hr/hr 
Connected.

SQL> exec dbms_stats.gather_schema_stats('HR');

PL/SQL procedure successfully completed.

SQL> select table_name, num_rows from user_tables;

TABLE_NAME                       NUM_ROWS
------------------------------ ----------
JOB_HISTORY                            10
EMPLOYEES                             107
COUNTRIES                              25
JOBS                                   19
DEPARTMENTS                            27
LOCATIONS                              23
REGIONS                                 4

7 rows selected.

SQL> select * from REGIONS;

 REGION_ID REGION_NAME
---------- -------------------------
         1 Europe
         2 Americas
         3 Asia
         4 Middle East and Africa

SQL> create table regions_4_drop as select * from regions;
Table created.

SQL> drop table regions_4_drop;
Table dropped.

SQL> select * from regions_4_drop;
select * from regions_4_drop
              *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> -- upsss !!!! , let's see what we can do 

SQL> show recyclebin;
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
REGIONS_4_DROP   BIN$ZS8TMdYUqM3gUKjAZAEUvw==$0 TABLE        2018-02-14:15:57:49
       
SQL> select * from "BIN$ZS8TMdYUqM3gUKjAZAEUvw==$0";

 REGION_ID REGION_NAME
---------- -------------------------
         1 Europe
         2 Americas
         3 Asia
         4 Middle East and Africa

SQL> flashback table REGIONS_4_DROP to before drop;
Flashback complete.

SQL> select * from regions_4_drop;

 REGION_ID REGION_NAME
---------- -------------------------
         1 Europe
         2 Americas
         3 Asia
         4 Middle East and Africa

SQL> drop table regions_4_drop purge;
Table dropped.

SQL> show recyclebin;

SQL> -- upsss !!!! ,  it's gone - good luck with backups / see the flashback database 



Obrigado pela leitura.
Espero que este post o tenha ajudado.

After drop a table Oracle moves the table to the recycle bin [execpt with purge option], on this  post i'm sharing how to recover a from a "drop table" ,  how to check the data in recycle bin.

As '/ as sysdba',

SQL> alter user hr identified by hr account unlock;
User altered.

SQL> conn hr/hr 
Connected.

SQL> exec dbms_stats.gather_schema_stats('HR');

PL/SQL procedure successfully completed.

SQL> select table_name, num_rows from user_tables;

TABLE_NAME                       NUM_ROWS
------------------------------ ----------
JOB_HISTORY                            10
EMPLOYEES                             107
COUNTRIES                              25
JOBS                                   19
DEPARTMENTS                            27
LOCATIONS                              23
REGIONS                                 4

7 rows selected.

SQL> select * from REGIONS;

 REGION_ID REGION_NAME
---------- -------------------------
         1 Europe
         2 Americas
         3 Asia
         4 Middle East and Africa

SQL> create table regions_4_drop as select * from regions;
Table created.

SQL> drop table regions_4_drop;
Table dropped.

SQL> select * from regions_4_drop;
select * from regions_4_drop
              *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> -- upsss !!!! , let's see what we can do 

SQL> show recyclebin;
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
REGIONS_4_DROP   BIN$ZS8TMdYUqM3gUKjAZAEUvw==$0 TABLE        2018-02-14:15:57:49
       
SQL> select * from "BIN$ZS8TMdYUqM3gUKjAZAEUvw==$0";

 REGION_ID REGION_NAME
---------- -------------------------
         1 Europe
         2 Americas
         3 Asia
         4 Middle East and Africa

SQL> flashback table REGIONS_4_DROP to before drop;
Flashback complete.

SQL> select * from regions_4_drop;

 REGION_ID REGION_NAME
---------- -------------------------
         1 Europe
         2 Americas
         3 Asia
         4 Middle East and Africa

SQL> drop table regions_4_drop purge;
Table dropped.

SQL> show recyclebin;

SQL> -- upsss !!!! ,  it's gone - good luck with backups 



Thank you for reading.
hope this post was helpful.

Comments

Popular posts from this blog

DB - How to monitor Oracle datapump jobs

These days there is lot of work around database migrations not only but mainly to cloud providers. One of the ways to migrate Oracle databases is using data pump (expdp/impdp). In general works fine, it allows an easy way to bring the database even different OS. It is always good to monitor the progress, to know where we are and estimate how long we are from the end. In this post, I am sharing some queries to help with database monitoring progress. The queries can be easily tailed to various scenarios. Starting with a simple one - the track the number of objects loaded during an import operation. When there is a massive amount of errors during the import. Drop and run the import again. The bellow query can be useful also to monitor the number of objects if we are dropping the users. Here, I’m making the assumption there were no other database activity in progress on the last 24 hours. select owner, count(0) from dba_objects where owner in ( select username from dba_users where created...

DB – How to monitor Oracle database long ops ?

As DBAs, some questions we are often asked and to be fair we ask ourselfs when we are doing massive operations, are : Is the database doing something? How long the database takes to complete the task? There a data dictionary view, GV$SESSION_LONGOPS whom is really usefull for monitoring and to provide estimated time to get the task done. Starting with a first example, a query for general propose . set lines 240 col message form a100 col opname form a50 select * from ( select round(l.sofar/l.totalwork*100,2) as complete, --l.* l.sid, --l.opname, l.message, l.start_time, l.time_remaining/60 "minuts remaining", l.elapsed_seconds from gv$session_longops l where totalwork !=0 ) where complete < 100; The view is also usefull on specific operations such as Oracle Recovery Manager (RMAN) jobs monitoring, this query returns information about backup,restore and recovery. select sid, serial#,opname, context, sofar, totalwork, round(sofar/totalwork*100,2) "%_complet...

VM - Resize a .vdi disk

I created a VM with 10G disk, after the Linux 7 installation, and the first upgrade, decided was better to increase the disk to 50GB. This post , i'm sharing the steps and commands I ran to increase the disk size. Software : Host : Windows 10 Pro , Oracle VM 6.1.2 Guest : Red Hat Enterprise Linux Server release 7.1 (Maipo) / Oracle Linux Server release 7.1 Ok - the first step is to resize the *vdi disk on the host side. Open a PowerShell console in the VM folder (Left Shift + Mouse Right Click on Windows) Quick list and check on the files. PS D:\VMs\OracleLinux7_MSSQL> ls Directory: D:\VMs\OracleLinux7_MSSQL Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 09/02/2020 18:40 Logs -a---- 09/02/2020 18:41 5689 OracleLinux7_MSSQL.vbox -a---- 09/02/2020 18:41 5688 OracleLinux7_MSSQL.vbox-prev -a---- 09/02/2020 18:40 9268363264 OracleL...