Professional Documents
Culture Documents
Oracle Flashback Technology provides a set of features available on 9i or higher version that support viewing and rewinding data back and forth in time to recover from Logical Corruptions while the database is online. Flashback Technology gives you 6 different ways to track and fix logical corruption through different approach. - Oracle Flashback Query feature lets you specify a target time and then run queries against your database, viewing results as they would have appeared at that time. - Oracle Flashback Version Query lets you view all the versions of all the rows that ever existed in one or more tables in a specified time interval. - Oracle Flashback Transaction Query lets you view changes made by a single transaction, or by all the transactions during a period of time. - Oracle Flashback Table returns a table to its state at a previous point in time. - Oracle Flashback Drop reverses the effects of a DROP TABLE statement. - Oracle Flashback Database provides a more efficient alternative to database point-in-time recovery. This Document contain the step by step example of how to enable flash back on a DB, how to flash back some deleted rows, how to flash back dropped tables and how to flash back a database for point in time recovery.
select NAME,FLASHBACK_ON from v$database; archive log list show parameter undo_retention show parameter DB_FLASHBACK_RETENTION_TARGET show parameter db_recovery_file_dest show parameter db_recovery_file_dest_size
3. How to enable Flashback Feature on a Database. The Database must be started through SPFILE.
SQL> show parameter pfile NAME TYPE VALUE ------------------------ ----------- -----------------------------spfile string /opt/oracle/product10gR2/dbs/spfileboxirep.ora
SQL> show parameter undo_management NAME TYPE VALUE ------------------------------------ ----------- -----------------------------undo_management string AUTO
Set the Recovery file destination or flashback area which will contain all flash back logs depending on the undo retention period.
SQL> alter system set db_recovery_file_dest='/itlinux68db05/ORACLE/flashback' scope=both;
Set the recovery file destination size. This is the hard limit on the total space to be used by target database recovery files created in the flash recovery area.
Set the flash back retention target . This is the upper limit (in minutes) on how far back in time the database may be flashed back. How far back one can flashback a database depends on how much flashback data Oracle has kept in the flash recovery area.
SQL> select NAME, FLASHBACK_ON from v$database; NAME FLASHBACK_ON --------- -----------------BOXIREP YES SQL>
NOT NULL,
05-02-2008 10:21:46 SQL> insert into ftest values(101,'TABLE'); insert into ftest values(102,'TABLE'); insert into ftest values(103,'TABLE'); insert into ftest values(104,'TABLE'); 1 row created. 1 row created. 1 row created. 1 row created. SQL> SQL> select * from ftest; OBJECTID ALIAS ---------- -------------------101 TABLE 102 TABLE 103 TABLE 104 TABLE SQL> commit; Commit complete.
- Now try to identify the deleted records as requested by the user in flashback area.
select versions_starttime, versions_endtime, versions_xid,versions_operation, objectid from ftest versions between timestamp minvalue and maxvalue order by VERSIONS_STARTTIME / VERSIONS_STARTTIME --------------------------------------------------------------------------VERSIONS_ENDTIME VERSIONS_XID V ------------------------------------------------------------------------------------------ OBJECTID ----------
01000E00280A000
05-FEB-08 10.22.26 AM 05-FEB-08 10.23.02 AM 01000E00280A0000 I 103 VERSIONS_STARTTIME --------------------------------------------------------------------------VERSIONS_ENDTIME VERSIONS_XID V ------------------------------------------------------------------------------------------ OBJECTID ---------05-FEB-08 10.22.26 AM 05-FEB-08 10.23.02 AM 01000E00280A0000 I 104 05-FEB-08 10.22.26 AM 0 I 01000E00280A000
- Query these records using timestamp before actually recovering them. Use the VERSIONS_ENDTIME column value of the last query.
SQL> SELECT * FROM ftest HH:MI:SS'); OBJECTID ---------101 102 103 104 SQL> AS OF TIMESTAMP TO_TIMESTAMP('05-02-2008 10:23:02','DD-MM-YYYY
- Now insert back these records to the original table. You may insert these records to a new table in case the DML statement is an update to compare the old value with the new value.
SQL>INSERT INTO ftest (SELECT * FROM ftest 10:23:02','DD-MM-YYYY HH:MI:SS'); 4 rows created. Oracle Flashback Table: Returning Individual Tables to Past States AS OF TIMESTAMP TO_TIMESTAMP('05-02-2008
SQL> grant flashback on fsbtest.ftest to fsbtest; Grant succeeded. SQL> alter table fsbtest.ftest enable row movement; Table altered. SQL>SELECT * FROM ftest HH:MI:SS'); AS OF TIMESTAMP TO_TIMESTAMP('05-02-2008 10:23:02','DD-MM-YYYY
SQL> - Flash back the table to its before drop state. SQL> FLASHBACK TABLE fsbtest.ftest_drop TO BEFORE DROP; Flashback complete. SQL> show recyclebin; ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME ---------------- ------------------------------ ------------ ------------------DROP_TEST BIN$RF6Njc00PfngQBQKHZgNEg==$0 TABLE 2008-01-23:10:08:24 SQL> select TABLE_NAME, STATUS, DROPPED from user_tables where TABLE_NAME like'%FTEST_DROP %'; TABLE_NAME -----------------------------FTEST_DROP SQL> We can also use globalUID Name Original Name. STATUS DRO -------- --VALID NO to flash back in case of Multiple Objects With the Same
NAME TYPE VALUE ------------------------------------ ----------- -----------------------------undo_retention integer 172800 SQL> show parameter DB_FLASHBACK_RETENTION_TARGET NAME TYPE VALUE ------------------------------------ ----------- -----------------------------db_flashback_retention_target integer 1440 SQL> show parameter db_recovery_file_dest NAME -----------------------------------db_recovery_file_dest db_recovery_file_dest_size TYPE ----------string big integer VALUE -----------------------------/itlinux68db05/ORACLE/flashback 3G
In SQL mode The database must be in mount state to issue these commands:
SQL> FLASHBACK SQL> FLASHBACK SQL> FLASHBACK SQL> FLASHBACK HH:MI:SS'); DATABASE TO SCN 11259789; DATABASE TO SEQUENCE 5304; DATABASE TO TIME (SYSDATE-1/24); DATABASE TO TIME TO_TIMESTAMP('05-02-2008 10:23:45','DD-MM-YYYY