Thursday, September 20, 2012
Table level Recovery using Flashback Table
---------------------------------------------------Recover Dropped Table from Recyclebin using Flashback Table-------------------------
Oracle Flashback Table enables you to restore a table to its state as of a previous point in time. It provides a fast, online solution for recovering a table that has been accidentally modified or deleted by a user or application. In many
cases, Oracle Flashback Table eliminates the need for you to perform more complicated point-in-time recovery operations.
Oracle Flashback Table:
Restores all data in a specified table to a previous point in time described by a timestamp or SCN.
Performs the restore operation online.
Automatically maintains all of the table attributes, such as indexes, triggers, and constraints that are necessary for an application to function with the flashed-back table.
Maintains any remote state in a distributed environment. For example, all of the table modifications required by replication if a replicated table is flashed back.
Maintains data integrity as specified by constraints. Tables are flashed back provided none of the table constraints are violated. This includes any referential integrity constraints specified between a table included in the FLASHBACK
TABLE statement and another table that is not included in the FLASHBACK TABLE statement.
Even after a flashback operation, the data in the original table is not lost. You can later revert to the original state.
FLASHBACK TABLE <table_name> TO BEFORE DROP;
Some other variations of the flashback database command include.
FLASHBACK DATABASE TO TIMESTAMP my_date;
FLASHBACK DATABASE TO BEFORE TIMESTAMP my_date;
FLASHBACK DATABASE TO SCN my_scn;
FLASHBACK DATABASE TO BEFORE SCN my_scn;
--------------------------------------------------Recover deleted Table Data from Recyclebin using Flashback Table---------------------
On Oracle Database 11g (10gR2...), we can rewind one or more tables back to their contents at a previous time without affecting other database objects.
Before we use Flashback Table, We must enable row movement on the table. because rowids will change after the flashback.
Example: Flashback the table back to previous time using SCN
select count(*) from LDBO.test;
COUNT(*)
----------
68781
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
-----------
1584494
SQL> delete from LDBO.test where rownum <= 50000;
50000 rows deleted.
SQL> commit;
Commit complete.
SQL> select count(*) from LDBO.test;
COUNT(*)
----------
18781
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
-----------
1587106
Enable row movement:
SQL> alter table LDBO.test enable row movement;
Table altered.
SQL> FLASHBACK TABLE LDBO.test to scn 1584494;
Flashback complete.
SQL> select count(*) from LDBO.test;
QL> alter table LDBO.test disable row movement;
Table altered.
We can rewind the table back to previous time using timestamp:
SQL> alter session set nls_date_format='YYYY/MM/DD HH24:MI:SS';
Session altered.
SQL> select sysdate from dual;
SYSDATE
-------------------
2009/08/30 17:01:09
SQL> delete from LDBO.test ;
68781 rows deleted.
SQL> commit;
Commit complete.
SQL> select sysdate from dual;
SYSDATE
-------------------
2009/08/30 17:03:18
SQL> select count(*) from LDBO.test;
COUNT(*)
----------
0
SQL> alter table LDBO.test enable row movement;
Table altered.
SQL> flashback table LDBO.test to timestamp TO_TIMESTAMP('2009/08/30 17:01:09','YYYY/MM/DD HH24:MI:SS');
Flashback complete.
SQL> select count(*) from LDBO.test;
COUNT(*)
----------
68781
--------------------------------------------------------------------------------------------Flashback Table recover table to different table----------------------
FLASHBACK TABLE test TO BEFORE DROP RENAME TO test2;
flashback table LDBO.test to timestamp TO_TIMESTAMP('2009/08/30 17:01:09','YYYY/MM/DD HH24:MI:SS') RENAME TO test2;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment