Flashback Query allows the user to recover data to a point in time using SCN or a specific time. The undo tablespace and undo management features allow the user to reach back in time according to the parameters set. Suspending operations can allow the DBA to quickly correct problems and prevent down time. Export/Import allows for a quick recovery with new 9i features.
Setting up Oracle Flashback Query
In most cases, setting up Oracle Flashback Query on the database is quite simple.
To set up Oracle Flashback Query on the database, the DBA must accomplish the following tasks:
First, determine how far into the past the Flashback Query feature must reach.
The UNDO_RETENTION parameter can be set.
The UNDO_MANAGEMENT parameter must be set to = AUTO
An UNDO tablespace must be created with enough space available to accommodate the amount of data that will be updated through Flashback Query.
The EXECUTE privilege must be granted to any users or roles that will need to access the DBMS_FLASHBACK package.
The DBMS_FLASHBACK Package
DBMS_FLASHBACK package is used to implement Oracle Flashback Query. The package has several procedures as follows:
ENABLE_AT_TIME – This procedure allows the user or developer to enable Flashback for a certain time in the past.
The argument must be of the type TIMESTAMP . Either the TIMESTAMP format (according to the database NLS settings) or TO_TIMESTAMP function can be used to specify whatever timestamp format is desired.
The DBMS_FLASHBACK Package
Oracle will set the Flashback version of the database to a SCN that is within five minutes of the time specified.
If DBMS_FLASHBACK.ENABLE_AT_TIME is called without the TIMESAMP argument, Oracle will use the default, which is 12:00 A.M. of the present day.
The system clock will continue to report the real system time.
DML and DDL cannot be performed while in Flashback mode.
Cursors that are opened in flashback mode can be used to perform DML after flashback mode is cancelled.
ENABLE_AT_SYSTEM_CHANGE_NUMBER – This procedure allows the user or developer to enable Flashback for a certain system change number in the past.
The argument must of type NUMBER.
The DBMS_FLASHBACK Package
GET_SYSTEM_CHANGE_NUMBER – This is a function that returns the current system change number for the system. It can be used to determine the current SCN so that the current version of the database can be stored as a snapshot.
DISABLE – This procedure disabled the package.
Resumable Statement and DBMS_RESUMABLE
The DBMS_RESUMABLE package allows developers to write long running batch jobs without accommodating space-related errors.
Operations that run out of space can be suspended and then resumed from the point of suspension.
If an error situation occurs that requires DBA intervention, the DBA can temporarily suspend the operation until he or she corrects the condition and then resume the operation.
With DBMS_RESUMABLE , operations can automatically suspend themselves, wait for the error condition to be corrected, and then automatically resume and complete.
The transaction is suspended along with the operation. Resources are still held.
Multiple suspensions and resumptions can take place.
A timeout period (default two hours) can be set after which an operation will terminate.
DBMS_RESUMABLE – Procedures and Functions
SET_TIMEOUT() – This procedure sets the resumable timeout period for the current session only. The default timeout value for resumable statements is two hours.
SET_SESSION_TIMEOUT() – The timeout period can be set for any session with this procedure by supplying the session ID. The timeout period is specified in seconds.
GET_TIMEOUT() – This is a function that will return the current resumable timeout setting for this session.
GET_SESSION_TIMEOUT() – This function returns the timeout period that has been set for a session specified with the session ID.
SPACE_ERROR_INFO() – This function returns any information it can find in the error stack that is space-related. FALSE will be returned if no such information exists.
ABORT() – This procedure will cause a resumable operation to terminate with an exception.
After Suspend Database Trigger
If an operation suspends for any reason, there is good reason for the appropriate DBA to be notified. The new AFTER SUSPEND trigger can be used to perform this needed function .
New Export/Import feature
Export/Import in Flashback query mode can use the where clause to get only the records needed.
The export and import utility now supports the new parameters for resumable space allocation:
The Export and Import utilities also support the following new parameters:
FLASHBACK Query Advantages
Creates a read consistent view.
The time or SCN gives greater ability to recover to a point in time.
Tables and objects can be queried directly with select statements.
Constraints are in effect so application code is valid.
Cursors in flashback sessions can perform DDL after the session is terminated.
DBMS_FLASHBACK is designed for authorized users.
The EXPORT command supports exporting data at the tablespace level. The new TABLESPACES parameter supports exporting tablespaces.
Flashback Query Disadvantages
The execute privilege must be given to authorized users.
The DBA might be engaged in the event the authorized user is not able to recover the data appropriately to a point in time or SCN.
Space Requirements – The UNDO Tablspace most be large enough to hold all of the transactions that you are bringing back.
Performance – Possible degradation in performance for OLTP or mixed environment (OLTP and Batch).
The system clock time may not match the SCN, so, Flashback Query could think that your query time is earlier than the table creation time and throw an error.
Specifying a time will only find the flashback copy to the nearest five minute interval. This is also true of the get_system_change_number.
You can never flashback more than 5 days, irrespective of UNDO_RETENTION.
Where to Get More Information
Oracle9i Recovering Lost Data – Oracle Metalink – Doc 174425.1
Parameters FLASHBACK_SCN & FLASHBACK_TIME: Point in Time Export – Oracle Metalink – Doc 204334.1
Flashback Query: Confusion on SCN based – Oracle Metalink – Doc 302681.999
Oracle 9i New Features Flashback – Oracle Metalink – Doc 143217.1