Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
32
Добавлен:
16.04.2013
Размер:
4.96 Mб
Скачать

Flashback Tips

A DBA might also be interested in knowing all changes made in a certain time window. In our scenario, the DBA performs the following query to view the details of all transactions that executed since the erroneous transaction identified earlier (including the erroneous transaction itself):

SELECT xid, start_scn, commit_scn, operation, table_name, table_owner

FROM flashback_transaction_query

WHERE table_owner = 'HR' AND start_timestamp >=

TO_TIMESTAMP ('2002-04-16 11:00:00','YYYY-MM-DD HH:MI:SS');

XID

START_SCN

COMMIT_SCN

OPERATION

TABLE_NAME

TABLE_OWNER

----------------

---------

----------

---------

----------

-----------

0004000700000058

195245

195246

UPDATE

EMP

HR

0004000700000058

195245

195246

UPDATE

EMP

HR

0004000700000058

195245

195246

INSERT

EMP

HR

000200030000002D

195243

195244

DELETE

EMP

HR

000200030000002D

195243

195244

INSERT

DEPT

HR

000200030000002D

195243

195244

UPDATE

EMP

HR

6 rows selected

Flashback Tips

The following tips and restrictions apply to using flashback features.

Flashback Tips – Performance

For better performance, generate statistics on all tables involved in a Flashback Query by using the DBMS_STATS package, and keep the statistics current. Flashback Query always uses the cost-based optimizer, which relies on these statistics.

The performance of a query into the past depends on how much undo data must be accessed. For better performance, use queries to select small sets of past data using indexes, not to scan entire tables. If you must do a full table scan, consider adding a parallel hint to the query.

The performance cost in I/O is the cost of paging in data and undo blocks that are not already in the buffer cache. The performance cost in CPU use is the cost of applying undo information to affected data blocks. When operating on changes in the recent past, flashback features essentially CPU bound.

Using Flashback Features 15-15

Flashback Tips

Use index structures for Flashback Version Query: the database keeps undo data for index changes as well as data changes. Performance of index lookup-based Flashback Version Query is an order of magnitude faster than the full table scans that are otherwise needed.

In a Flashback Transaction Query, the type of the xid column is RAW(8). To take advantage of the index built on the xid column, use the HEXTORAW conversion function: HEXTORAW(xid).

Flashback Query against a materialized view does not take advantage of query rewrite optimizations.

See Also: Oracle Database Performance Tuning Guide

Flashback Tips – General

Use the DBMS_FLASHBACK package or other flashback features? Use ENABLE/DISABLE calls to the DBMS_FLASHBACK package around SQL code that you do not control, or when you want to use the same past time for several consecutive queries. Use Flashback Query, Flashback Version Query, or Flashback Transaction Query for SQL that you write, for convenience. A Flashback Query, for example, is flexible enough to do comparisons and store results in a single query.

To obtain an SCN to use later with a flashback feature, use DBMS_ FLASHBACK.GET_SYSTEM_CHANGE_NUMBER.

You can compute or retrieve a past time to use in a query by using a function return value as a timestamp or SCN argument. For example, you can perform date and time calculations by adding or subtracting an INTERVAL value to the value of the SYSTIMESTAMP function.

You can query locally or remotely (Flashback Query, Flashback Version Query, or Flashback Transaction Query). for example here is a remote Flashback Query:

(SELECT * FROM employee@some_remote_host AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '60' MINUTE);

To ensure database consistency, always perform a COMMIT or ROLLBACK operation before querying past data.

Remember that all flashback processing is done using the current session settings, such as national language and character set, not the settings that were in effect at the time being queried.

15-16 Oracle Database Application Developer's Guide - Fundamentals

Flashback Tips

Some DDLs that alter the structure of a table, such as drop/modify column, move table, drop partition, and truncate table/partition, invalidate any existing undo data for the table. It is not possible to retrieve data from a point earlier than the time such DDLs were executed. Trying such a query results in error ORA-1466. This restriction does not apply to DDL operations that alter the storage attributes of a table, such as PCTFREE, INITTRANS and MAXTRANS.

Use an SCN to query past data at a precise time. If you use a timestamp, the actual time queried might be up to 3 seconds earlier than the time you specify. Internally, Oracle Database uses SCNs; these are mapped to timestamps at a granularity of every 3 seconds.

For example, assume that the SCN values 1000 and 1005 are mapped to the times 8:41 and 8:46 AM respectively. A query for a time between 8:41:00 and 8:45:59 AM is mapped to SCN 1000; a Flashback Query for 8:46 AM is mapped to SCN 1005.

Due to this time-to-SCN mapping, if you specify a time that is slightly after a DDL operation (such as a table creation) the database might actually use an SCN that is just before the DDL operation. This can result in error ORA-1466.

You cannot retrieve past data from a V$ view in the data dictionary. Performing a query on such a view always returns the current data. You can, however, perform queries on past data in other views of the data dictionary, such as

USER_TABLES.

Using Flashback Features 15-17

Flashback Tips

15-18 Oracle Database Application Developer's Guide - Fundamentals

Тут вы можете оставить комментарий к выбранному абзацу или сообщить об ошибке.

Оставленные комментарии видны всем.

Соседние файлы в папке Oracle 10g