Globusz® Publishing 




Flashback Technology Enhancements



    Using the Flashback Technology

You can use the flashback technology at the database, table, and transaction levels:

   General Flashback Technology

Guaranteed Undo Retention

The initialization parameter UNDO_RETENTION enables you to specify the length of time Oracle must retain undo information in the undo segments.

Default value: 900 (in seconds)
Modifiable: ALTER SYSTEM
Range: 0 to 232 – 1

By default, Oracle doesn’t guarantee undo retention.

Methods to specify Undo Guarantee:

CREATE UNDO TABLESPACE test1

DATAFILE 'c:\oracle\oradata\undotbs_01.dbf'

SIZE 100M AUTOEXTEND ON

RETENTION GUARANTEE

ALTER TABLESPACE test1 RETENTION GUARANTEE

Note: You can use the RETENTION NOGUARANTEE clause to turn off the guaranteed retention of undo information.

Note: The amount of time for which undo is retained for the Oracle Database for the current undo tablespace can be obtained by querying the TUNED_UNDORETENTION column of the V$UNDOSTAT dynamic performance view.

Note: Use Oracle’s Undo Advisor to get approximate undo parameter values as well as suggestions regarding the sizing of your undo tablespace to successfully support flashback for a specified time.

Time Mapping Granularity

SELECT current_scn, SCN_TO_TIMESTAMP(current_scn) FROM v$database

   Flashback Database

How Flashback Database Works

Flashback Database Considerations

Configuring Flashback Database

1. Ensure that your database is in the archivelog mode.

V$DATABASE (cols: logmode)

ARCHIVE LOG LIST (in SQL*Plus)

2. Your database must be using the flash recovery area.

SELECT VALUE FROM V$PARAMETER WHERE NAME = 'db_recovery_file_dest'

3. You must set the initialization parameter DB_FLASHBACK_RETENTION_TARGET to set your flashback retention target (in minutes).

ALTER SYSTEM SET DB_FLASHBACK_RETENTION_TARGET=1440

4. Shut down the database and restart in the MOUNT EXCLUSIVE mode.

5. Turn the flashback database feature on with the following command:

ALTER DATABASE FLASHBACK ON;

6. Use the ALTER DATABASE OPEN command to open the database.

SELECT FLASHBACK_ON FROM V$DATABASE;

Note: You can turn the feature off by using the ALTER DATABASE FLASHBACK OFF command while the database in the MOUNT EXCLUSIVE mode. When you do so, Oracle deletes all flashback database logs in the flash recovery area.

Note: If you don’t want certain tablespaces to be part of your flashback operations, issue the following command after setting the tablespace offline:

ALTER TABLESPACE USERS FLASHBACK OFF

Flashbacking a Database

  1. Restart the database in the MOUNT (exclusive) mode then issue one of the commands:

FLASHBACK DATABASE TO SCN 5964663

FLASHBACK DATABASE TO BEFORE SCN 5964663

FLASHBACK DATABASE TO TIMESTAMP (SYSDATE -1/24)

FLASHBACK DATABASE TO SEQUENCE 12345

  1. Open the database with READ ONLY option to check that the database flashed back to the correct time.
  2. If you decide to go back further in time, you can flashback the database again.
  3. If you determine that you flashed back too far into the past, you can use redo logs to roll forward.
  4. Open the database with RESETLOGS option:

ALTER DATABASE OPEN RESETLOGS

  1. If you want to completely undo the effects of the flashback database operation, just use the command RECOVER DATABASE to perform a complete recovery of the database.

Displaying Flashback Storage Information

In order to estimate the space you need to add to your flash recovery area for accommodating the flashback database logs:

SELECT ESTIMATED_FLASHBACK_SIZE, RETENTION_TARGET, FLASHBACK_SIZE FROM V$FLASHBACK_DATABASE_LOG

To really know how far back you can flashback your database at any given time, you must query the V$FLASHBACK_DATABASE_LOG in the following manner:

SELECT OLDEST_FLASHBACK_SCN, OLDEST_FLASHBACK_TIME FROM V$FLASHBACK_DATABASE_LOG

The view V$FLASHBACK_DATABASE_STATS helps you monitor the I/O overhead of logging flashback data.

BEGIN_TIME and END_TIME stand for the beginning and ending hourly time intervals for which the view’s statistics were collected. Oracle collects flashback data on an hourly basis for a maximum of 24 hours. If you issue a query on the table, however, it may return 25 rows, the 25th row being for the most recent fraction of time after the last (24th) row was logged in the view.

FLASHBACK_DATA stands for the number of bytes of flashback data written during the interval.

DB_DATA stands for the number of bytes of database data read and written during the interval.

REDO_DATA stands for the number of bytes of redo data written during the interval.

ESTIMATED_FLASHBACK_SIZE is identical to the value of the ESTIMATED_FLASHBACK_SIZE column in the V$FLASHBACK_DATABASE_LOG view.

   Flashback Drop

How the Flashback Drop Feature Works

Querying the Recycle Bin

You can view the contents of the recycle bin by using either the DBA_RECYCLEBIN or USER_RECYCLEBIN.

Alternatively, you can use the SHOW RECYCLEBIN command which shows only those objects that you can undrop.

Restoring Dropped Tables

In order to restore a dropped table:

FLASHBACK TABLE persons TO BEFORE DROP

FLASHBACK TABLE "BIN$ksisyyg0TxKnt18rqukpQA==$0"

TO BEFORE DROP RENAME TO NEW_PERSONS

Note: W?hen you flashback a table, Oracle will recover the dependent objects (except bitmap indexes) as well, but they will continue to have their cryptic system-generated names.

If you drop and re-create a table with the same name, the recycle bin will have several versions of the dropped table, each with a unique system-generated table name. If you then issue a FLASHBACK TABLE... TO BEFORE DROP command, Oracle will simply recover the latest version of the table. If you don’t want Oracle to do this, you have the following options:

Permanently Removing Tables

DROP TABLE PERSONS PURGE

PURGE TABLE "BIN$Q1QZGCCMRSSCBBRN9IVWFA==$0"

PURGE TABLESPACE USERS USER SCOTT

PURGE RECYCLEBIN or PURGE USER_RECYCLEBIN will remove all objects belonging to the user issuing the command.

PURGE DBA_RECYCLEBIN command will remove all objects in the recycle bin. You must have the SYSDBA privilege to purge the entire recycle bin.

If you drop a tablespace, any objects belonging to the tablespace that are part of the recycle bin are purged immediately.

If you use the command DROP USER ... CASCADE, any objects in the recycle bin that belong to that user are automatically purged.

Restrictions on Flashback Drop

   Flashback Table

How Flashback Table Works

Flashback table technology uses undo information to restore data rows in changed blocks of tables.

Pre-requisites

ALTER TABLE persons ENABLE ROW MOVEMENT

How to Flashback a Table

First, it is useful to note the current SCN then issue the command:

FLASHBACK TABLE persons TO SCN 6039341

FLASHBACK TABLE persons TO TIMESTAMP TO_TIMESTAMP ('2004-07-04 08:05:00', 'YYYY-MM-DD HH24:MI:SS')

Oracle disables all relevant triggers by default and reenables them upon completing the table recovery. You may simply append the ENABLE TRIGGERS clause to your FLASHBACK TABLE command if you want to override this default behavior.

The persons table continues to be online and accessible to users for all queries. However, Oracle acquires exclusive DML locks on the table during the Flashback Table operation.

Undoing a Flashback Table Operation

It is important to note your current SCN before using a Flashback Table operation.

Use the FLASHBACK TABLE statement again to go back to just before you were when you issued the first statement.

Restrictions on Flashback Table

   Row Level Flashback Features

The value of the UNDO_RETENTION parameter determines the length of time your users can flashback their queries.

Flashback Query (SELECT...AS OF)

SELECT * FROM persons AS OF TIMESTAMP

TO_TIMESTAMP('2004-07-04 08:05:00', 'YYYY-MM-DD HH:MI:SS') WHERE NAME = 'ALAPATI'

Flashback Versions Query

When you issue a SELECT statement using the VERSIONS clause, Oracle will return the different committed versions of the same row between two SCNs or two timestamps.

VERSIONS BETWEEN

{SCN | TIMESTAMP} start|MINVALUE AND

end|MAXVALUE

[AS OF {SCN|TIMESTAMP expr}]

Here is a brief explanation of pseudocolumns that will be part of the flashback versions query output:

VERSIONS_STARTSCN and VERSIONS_STARTTIME This pseudocolumn tells you the SCN and timestamp when this particular row was first created.

VERSIONS_ENDSCN and VERSIONS_ENDTIME These pseudocolumns tell you when this particular row expired.

VERSIONS_OPERATION This pseudocolumn provides you with information as to the type of DML activity that was performed on the particualr row. The DML activities are indicated by letters: I stands for insert, D for delete, and U for update.

VERSIONS_XID This pseudocolumn stands for the unique transaction identifier of the transaction that resulted in this row version.

Note: If the VERSIONS_STARTSCN and the VERSIONS_STARTTIME are NULL, then the row was created before the lower bound specified by your BETWEEN clause.

Note: If the VERSIONS_ENDSCN and the VERSIONS_ENDTIME are NULL, this means that this row version is current when you tried to use the Flashback Versions Query operation, or the row was part of a delete operation.

Note: An index-organized table (IOT) will show an update operation as a separate insert and a delete operation.

Example:

SELECT VERSIONS_XID XID, VERSIONS_STARTSCN START_SCN, VERSIONS_ENDSCN END_SCN, VERSIONS_OPERATION OPERATION, empname, salary

FROM hr.emp

VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE

AS OF SCN 113900

WHERE empno = 111

Flashback Transaction Query

FLASHBACK_TRANSACTION_QUERY lets you identify which transaction or transactions were responsible for certain changes during a certain interval.

Its columns are:

XID, START_SCN, START_TIMESTAMP, COMMIT_SCN, COMMIT_TIMESTAMP, LOGON_USER, UNDO_CHANGE#, OPERATION, TABLE_NAME, TABLE_OWNER, ROW_ID, UNDO_SQL

Note: You must have the SELECT ANY TRANSACTION system privilege to query the FLASHBACK_TRANSACTION_QUERY view.

Using Flashback Transaction Query and Flashback Versions Query

SELECT XID, START_SCN START, COMMIT_SCN COMMIT,

OPERATION OP, LOGON_USER USER,

UNDO_SQL FROM FLASHBACK_TRANSACTION_QUERY

WHERE XID = HEXTORAW('000200030000002D')

Value passed to HEXTORAW function obtained from Flashback versions query of an old row version to undo or audit.

Flashback Transaction Query Considerations

ALTER DATABASE ADD SUPPLEMENT LOG DATA



Use and reproduction of this material is governed by Globusz® Publishing's standard terms and conditions.