1 Query FlashbackWhat it’s for? · Recovering deleted or incorrectly modified data. · Compare Current Data with Old Data. · See historic data. · Avoid the use of temporal data.
To flashback in time Oracle only read the needed undo segments and display the information, this isn’t a new technology is the same technology to get a consistent query, to the point the query started.
DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER RETURN NUMBER; Get the SCN number EXEC DBMS_FLASHBACK.ENABLE_AT_TIME ( TIMESTAMP '2002-01-01 00:00:00'); Enable the session in flashback mode at approximately that time EXEC DBMS_FLASHBACK.ENABLE_AT_SYSTEM_CHANGE_NUMBER(3254658); Enable the session in flashback mode exactly at that SCN EXEC DBMS_FLASHBACK.DISABLE; Disable the flashback mode SELECT FROM AS OF TIMESTAMP '2002-01-01 00:00:00' Select the table in flashback mode at approximately that time SELECT FROM A AS OF SCN 3254658; Select the table in flashback mode exactly at that SCN
Select small sets of data using indexes, rather than queries that require full table scans. If you must do a full table scan, consider adding a parallel hint to the query.
FLASHBACK ANY TABLE to issue a flashback on any table, view or materialized view in any schema. Or FLASHBACK object privilege to specific objects. ( Not needed for DBMS_FLASBACK package). Privilege to execute DBMS_FLASBACK package, if you use that package.
We start creating the table, inserting the values and getting the proper SCN, after every operation. 14:34:07 SQL> CREATE TABLE A ( B VARCHAR2(1)) 14:34:23 2 ; Table created.
14:34:25 SQL> SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL; GET_SYSTEM_CHANGE_NUMBER ------------------------ 3254181
14:57:58 SQL> INSERT INTO A VALUES( '1'); GET_SYSTEM_CHANGE_NUMBER ------------------------ 3254652
14:58:22 SQL> INSERT INTO A VALUES( '2'); GET_SYSTEM_CHANGE_NUMBER ------------------------ 3254653
14:58:26 SQL> INSERT INTO A VALUES( '3'); GET_SYSTEM_CHANGE_NUMBER ------------------------ 3254654
scott@ORA920> scott@ORA920> select a.ename, b.ename 2 from emp a, emp as of scn &scn b 3 where a.empno = b.empno 4 / old 2: from emp a, emp as of scn &scn b new 2: from emp a, emp as of scn 25585211 b
ENAME ENAME ---------- ---------- smith SMITH allen ALLEN ward WARD jones JONES martin MARTIN blake BLAKE clark CLARK scott SCOTT king KING turner TURNER adams ADAMS james JAMES ford FORD miller MILLER 14 rows selected.
To get precision in your flashback queries is better to save the SCN number periodically. The system change number (SCN), a version number for the database that is incremented on every commit. You can use the function In Oracle 9i DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER In 8i you can use USERENV('COMMITSCN')
create or replace procedure save_scn as pragma autonomous_transaction/* commit independently*/; l_scn number; begin insert into scn values ( SYSDATE, DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER ); commit; end; /
CREATE VIEW vew_example AS SELECT * FROM example AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '120' MINUTE); When using this technique, remember that daylight savings time and leap years can cause anomalous results. For example, SYSDATE - 1might refer to 23 or 25 hours ago, shortly after a change in daylight savings time.
You can export using flashback query: Using the parameter flashback_scn, flashback_time. For example exp system/manager full=y file=flashbacktest.dmp flashback_scn=10002
The period of UNDO retention is not guaranteed (unless you do so in 10gR2 and upward) This means if some operation requires the space, it will overwrite your previous data, the advice is to do a CREATE TABLE AS SELECT AS OF, as sonn as you can, to guarantee not to lose that information.
DDL statements like drop, modify, move, truncate invalidates undo data. Not including storage attributes of a table as INITTRANS, MAXTRANS. This situation creates the ORA-01466 unable to read data - table definition has changed Only the data if affected by a flashback query. Other information is got from data dictionary, including current character set.
You can flashback without using the DBMS_FLASHBACK package. SELECT AS OF SCN, …. CREATE TABLE AS SELECT AS OF SCN…. SELECT AS OF TIMESTAMP….. CREATE TABLE AS SELECT AS OF TIMESTAMP…..