Platinum Solutions Corporate Website


Using Flashback queries to recover data

The answer you entered to the math problem is incorrect.

In version 9i, Oracle introduced a new feature called Flashback, that uses undo segments (rollback segments for old timers) to recover from a user error even though the transaction has been committed.   There are some initialization parameters that need to be set for it to work- UNDO_MANAGEMENT should be set at AUTO, UNDO_RETENTION should be set to the amount of time (in seconds) that committed undo information is retained for.  In addition, users who will be doing "flashback queries" need execute rights on the DBMS_FLASHBACK package and FLASHBACK privileges on the table(s) in need of recovery.

There are two different methods for using FLASHBACK, the easiest  of which is to use the AS OF clause in SQL to specify the past timestamp for which you want to see data.  The simplest way to use the results of a flashback query to change the data in the database is to use the AS OF clause inside INSERT or CREATE TABLE AS SELECT statements.  (Example: 

INSERT INTO USERS 
(SELECT * FROM USERS AS OF TIMESTAMP
TO_TIMESTAMP ('22-APR-03 9:04:58','DD-MON-YY HH24: MI: SS')
MINUS
SELECT * FROM USERS);

(The other method of  implementing Flashback involves using the DBMS_FLASHBACK package, but that requires opening a cursor and then fetching the results from past data from it for inserting or updating  against the current state of the database.)

You can also flashback to a System Change Number (SCN) which is more precise, but it requires you to know the SCN in advance (DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER will return the current SCN). 

(Example: 

INSERT INTO USERS 
(SELECT * FROM USERS AS OF SCN 1777034 MINUS
SELECT * FROM USERS);

For the most part, Flashback queries are limited to the last five days since they use the System Change Number (SCN).  Oracle9i tracks SCNs at five-minute intervals and logs the information for the last five days of operation. The SCN/time mapping is recorded every five minutes after database startup.  Even when AS OF TIMESTAMP is used, it is still the SCN the package is using and it will find the SCN within five minutes of the  time specified.

Flashback queries provide a way of recovering recently deleted data without having to resort to the IMP utility or a point-in-time recovery. 

Comments

Post new comment

Please solve the math problem above and type in the result. e.g. for 1+1, type 2.
The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.

More information about formatting options