Oracle Flashback Technology

Flashback Recovery is a new enhancement to the 10g database for the DBA's toolkit. Effectively, it's an "Oh shit!" protection mechanism for DBAs as it reduces recovery time from hours to minutes. Ask any DBA about the main cause of application outage - other than hardware failure - and the answer will be "human error". Such errors can result in logical data corruption and can bring down the complete system. Part of being human is making mistakes. Without advance planning, these errors are extremely difficult to avoid, and can be very difficult to recover from. Typical user-errors may include the accidental deletion of valuable data, deleting the wrong data, or dropping the wrong table. So, the big question is: How can we protect a database from human error? The answer is a technology called "Flashback" - a major enhancement in 10g, as it revolutionizes recovery by working just on the changed data. Flashback provides: An effective way to recover from complex human errors Faster database point-in-time recovery Simplified management and administration Little performance overhead The performance overhead of enabling Flashback Database is less than 2%. While you may not be willing to sacrifice any performance overhead for your production database, think about the trade-off. If you could recover the database in minutes instead of hours, saving your company millions of dollars in lost revenue, wouldn't you be willing to give 2% of the resources to Flashback Database? Below is a chat to show how quickly Flashback can recover your database.

Issue the alter database archivelog command when the database is mounted. alter system set DB_FLASHBACK_RETENTION_TARGET=4320. Suppose. Flashback Drop (Recycle Bin) 6. to find out what data has been lost. i. Flashback Query 2. 'YYYY-MM-DD HH:MI:SS') WHERE name = 'JON'. . the DBA can then re-insert the lost data in the database. You can use a Flashback Query to retrieve data as it existed at some time in the past. for instance. and the DBA knows that at 9:30AM the data for JON was correctly stored in the database. April 4.g. This update then restores John's information to the employee table: SQL> INSERT INTO employee (SELECT * FROM employee AS OF TIMESTAMP TO_TIMESTAMP('2006-04-04 09:30:00'. alter system set DB_RECOVERY_FILE_DEST='/u02/fra'. alter system set DB_RECOVERY_FILE_DEST_SIZE=536870912. Flashback Version Query 3. It returns committed data that was current at that point in time.Architecture: There are some basic prerequisites for Flashback recovery: The database should be in Archive Log Mode. 'YYYY-MM-DD HH:MI:SS') WHERE name = 'JON').e. The DBA can use a Flashback Query to examine the contents of the table at 9:30. 72 hours DB_RECOVERY_FILE_DEST_SIZE: This specifies the maximum data that can be retained. The query explicitly references a past time using a timestamp or SCN. Flashback Database Flashback Query: You can perform a Flashback Query using a SELECT statement with an AS OF clause. E. Types of Flashback recoveries There are six basic types of Flashback recovery. If appropriate. Flashback Transaction Query 4. E. i.e. Example: This example uses a Flashback Query to examine the state of a table at a specified time in the past. Some of the parameters should be set as follows: DB_FLASHBACK_RETENTION_TARGET: This specifies the time limit for deleted data to be maintained in the database. The following query retrieves the state of the employee record for JOHN at 9:30AM. E.g. discussed below in detail: 1.g. Flashback Table 5. that a DBA discovers at 12:30 PM that data for employee JON has been deleted from the employee table. 512 MB DB_RECOVERY_FILE_DEST: This specifies the destination for the flashback data. 2006: SQL> SELECT * FROM employee AS OF TIMESTAMP TO_TIMESTAMP('2006-04-04 09:30:00'.

and then 13 (with a commit after every update). Various elements for this are shown below: VERSIONS_XID .---------01-DEC-06 03. and update) VERSIONS_STARTSCN . versions_endtime.57. then 12.The SCN in which this row version was changed. insert.39 PM 000A000A00000029 U 11 01-DEC-06 03. "How did this happen?". l_timestamp := SCN_TO_TIMESTAMP(l_scn). . Now everyone really is accountable for his or her actions.57. versions_operation. BEGIN l_scn := TIMESTAMP_TO_SCN(SYSTIMESTAMP .---------------. END.Flashback Query Functions The TIMESTAMP_TO_SCN and SCN_TO_TIMESTAMP functions have been added to SQL and PL/SQL to simplify flashback operations: DECLARE l_scn NUMBER. dept from Dept versions between timestamp minvalue and maxvalue order by VERSIONS_STARTTIME VERSIONS_STARTTIME VERSIONS_ENDTIME VERSIONS_XID V Dept ---------------------.30 PM 0002002800000C61 I 10 01-DEC-06 03.output: update "SCOTT".57. You can build customized applications for auditing purposes. but this is a powerful tool for the application's developer as well. versions_xid.55 PM 000A000B00000029 U 12 We can automatically generate the undo statement using: SQL> SELECT UNDO_SQL FROM FLASHBACK_TRANSACTION_QUERY WHERE XID = '000A000A00000029'.The SCN in which this row version first occurred VERSIONS_ENDSCN .The transaction id that created this version of the row VERSIONS_OPERATION .57."Dept" set "Dept" = '12' where ROWID = 'AAAMicAAEAAAAA/AAA'..The action that created this version of the row (such as delete.12 PM 01-DEC-06 03. Thus we have done three updates: SQL> select versions_starttime. l_timestamp TIMESTAMP. For example: we use the Dept table in Scott schema and update dept 10 to 11.57.1/24).57. Not only can the DBA run a manual analysis.---------------------.30 PM 01-DEC-06 03. / Flashback Version Query The Flashback Version Query is a powerful tool for the DBA to run analysis and answer the question. Flashback Transaction Query .39 PM 01-DEC-06 03.

operation OP."DEPT" 000200030000002D 195243 195244 UPDATE HR update "HR". XID START COMMIT OP USER UNDO_SQL ---------------. commit_scn COMMIT. 000200030000002D 195243 113565 BEGIN HR 4 rows selected.'655'). but by then it's too late . Users soon realize their mistake. Flashback Table Recovering Tables Using the Flashback Table Feature Just as the flashback query helps to retrieve rows of a table. including SQL code that you can use to undo each of the changes made by the transaction.----. For example: SQL> SELECT xid. undo_sql FROM flashback_transaction_query WHERE xid = HEXTORAW('000200030000002D')."EMP" ("EMPNO".'DD-MON-YY HH24: MI: SS').-----. The following simple command will take us to the table state at the specified timestamp: SQL> FLASHBACK TABLE Employee TO TIMESTAMP ('13-SEP-06 8:50:58'. It uses the XID from above and shows the complete transaction steps for that XID."EMPNAME". .Auditing Table Changes Using Flashback Transaction Query A Flashback Transaction Query is a query on a view called FLASHBACK_TRANSACTION_QUERY. start_scn START. FLASHBACK TABLE helps to restore the state of a table to a certain point in time ."EMP" set "SALARY" = '555' where ROWID = 'AAAKD2AABAAAJ29AAA'. etc.even if a table structure change has occurred since then. delete from "HR"."SALARY") values ('111'. constraints.and until now there has been no easy way to recover those dropped tables. 000200030000002D 195243 195244 INSERT HR where ROWID = 'AAAKD4AABAAAJ3BAAB'. logon_user USER. indexes.'Mike'. triggers.--------------------------000200030000002D 195243 195244 DELETE HR insert into "HR".----. Flashback Drop (Recycle Bin) The accidental dropping of objects has always been a problem for users and DBAs alike. You use a Flashback Transaction Query to obtain transaction information.

or even use Flashback Query on it. The Recycle Bin The Recycle Bin is a virtual container for all dropped objects. Dropped tables and any associated objects such as indexes. FLASHBACK DATABASE TO BEFORE TIMESTAMP my_date.Check that the table is gone. For example: -. You can continue to access the data in a dropped table. to correct any logical data corruption. open the database with Resetlogs. and other dependent objects are not moved. ALTER DATABASE OPEN RESETLOGS. CREATE TABLE flashback_database_test (id NUMBER(10) --Flashback 5 Minutes CONN sys/password AS SYSDBA SHUTDOWN IMMEDIATE STARTUP MOUNT EXCLUSIVE FLASHBACK DATABASE TO TIMESTAMP SYSDATE-(1/24/12). -. the dropped table EMP remains in the USERS tablespace. the objects occupy the same space as when they were created. FLASHBACK DATABASE TO SCN my_scn When the system comes back with FLASHBACK COMPLETE. nested tables. FLASHBACK DATABASE TO TIMESTAMP my_date. DESC flashback_database_test . But what if something happens to the whole database? This recovery quickly rewinds the complete database to a previous time. SQL> FLASHBACK TABLE dept_test TO BEFORE DROP. constraints. When a user drops a table. If table EMP was created in the USERS tablespace.Create a dummy table. Under its lid.Flashback Drop provides a safety net when dropping objects in Oracle Database 10g. Flashback Database We have been talking about object recovery. they are simply renamed with the prefix BIN$$. Some of the options are: FLASHBACK DATABASE TO TIMESTAMP SYSDATE-(1/24/12). Oracle automatically places it into the Recycle Bin. This can be used with both RMAN & SQL*Plus.

Sign up to vote on this title
UsefulNot useful