Oracle Flashback Technology
Oracle Flashback Technology
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.
Architecture:
There are some basic prerequisites for Flashback recovery:
The database should be in Archive Log Mode. Issue the alter database
archivelog command when the database is mounted.
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. E.g. alter system set
DB_FLASHBACK_RETENTION_TARGET=4320, i.e. 72 hours
DB_RECOVERY_FILE_DEST_SIZE: This specifies the maximum data that can be
retained. E.g. alter system set DB_RECOVERY_FILE_DEST_SIZE=536870912, i.e.
512 MB
DB_RECOVERY_FILE_DEST: This specifies the destination for the flashback data.
E.g. alter system set DB_RECOVERY_FILE_DEST='/u02/fra';
Types of Flashback recoveries
There are six basic types of Flashback recovery, discussed below in detail:
1. Flashback Query
2. Flashback Version Query
3. Flashback Transaction Query
4. Flashback Table
5. Flashback Drop (Recycle Bin)
6. Flashback Database
Flashback Query:
You can perform a Flashback Query using a SELECT statement with an AS OF
clause. You can use a Flashback Query to retrieve data as it existed at some
time in the past. The query explicitly references a past time using a timestamp
or SCN. It returns committed data that was current at that point in time.
Example:
This example uses a Flashback Query to examine the state of a table at a
specified time in the past. Suppose, for instance, that a DBA discovers at 12:30
PM that data for employee JON has been deleted from the employee table, and
the DBA knows that at 9:30AM the data for JON was correctly stored in the
database. The DBA can use a Flashback Query to examine the contents of the
table at 9:30, to find out what data has been lost. If appropriate, the DBA can
then re-insert the lost data in the database.
The following query retrieves the state of the employee record for JOHN at
9:30AM, April 4, 2006:
SQL> SELECT * FROM employee AS OF TIMESTAMP
TO_TIMESTAMP('2006-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')
WHERE name = 'JON';
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', 'YYYY-MM-DD HH:MI:SS')
WHERE name = 'JON');
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;
l_timestamp TIMESTAMP;
BEGIN
l_scn := TIMESTAMP_TO_SCN(SYSTIMESTAMP - 1/24);
l_timestamp := SCN_TO_TIMESTAMP(l_scn);
END;
/
4 rows selected.
Flashback Table
Just as the flashback query helps to retrieve rows of a table, FLASHBACK TABLE
helps to restore the state of a table to a certain point in time - even if a table
structure change has occurred since then. 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','DD-MON-YY HH24: MI: SS');
Flashback Database
We have been talking about object recovery. But what if something happens to
the whole database? This recovery quickly rewinds the complete database to a
previous time, to correct any logical data corruption. This can be used with
both RMAN & SQL*Plus.
Some of the options are:
FLASHBACK DATABASE TO TIMESTAMP SYSDATE-(1/24/12);
FLASHBACK DATABASE TO TIMESTAMP my_date;
FLASHBACK DATABASE TO BEFORE TIMESTAMP my_date;
FLASHBACK DATABASE TO SCN my_scn
When the system comes back with FLASHBACK COMPLETE, open the database
with Resetlogs.
For example:
-- Create a dummy table.
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);
ALTER DATABASE OPEN RESETLOGS;