Flashback Data Archive feature is part of Oracle Total Recall technology. Flashback Data Archive feature lets you to track changes made in any number of tables for any given retention time. The retention time can be some days or months or years.
Flashback data archives retain historical data for the time duration specified using the RETENTION
parameter. Historical data can be queried using the Flashback Query AS
OF
clause. Archived historic data that has aged beyond the specified retention period is automatically purged.
This feature is supported only Oracle 11g Enterprise Edition. It is not available in Standard or Express editions.
Lets see an example.
Step 1:- Create Flashback data archive tablespace.
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
SQL> create tablespace FB_Storage datafile '/u01/app/oracle11g/oradata/DB11/datafile/fdstore.dbf'
2 size 100m autoextend on segment space management auto;
Tablespace created.
Step 2:- Create Flashback Archive
SQL> create flashback archive default FB_Arch1 tablespace FB_Storage quota 1g retention 1 year;
Flashback archive created.
Step 3:- Turn on Flashback archive for tables you want to track.
For Example to enable flashback archive for table Scott.emp
(i) Grant Flashback archive privilege
SQL> grant flashback archive on fb_arch1 to scott;
Grant succeeded.
SQL> connect scott/tiger
Connected.
(ii) Enable flashback archive for table
SQL> alter table emp flashback archive;
Table altered.
Step 4:- Flashback Example.
Suppose a user has deleted rows from emp by giving a delete statement like this
SQL> set time on
19:57:32 SQL> select * from emp;
DEPTNO DNAME LOC
---------- -------------- -------------
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
19:57:56 SQL>
19:57:59 SQL>
19:57:59 SQL>
19:57:59 SQL>
19:57:59 SQL> delete from emp where deptno=30;
1 row deleted.
19:58:25 SQL> commit;
Commit complete.
To View the state of table emp 10 minutes before
19:58:29 SQL> select * from emp as of timestamp sysdate - 10 / (24*60);
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
Versions Query (11gR2 only) (To see what changes are made to Emp No. 7902 between last 15 minutes
22:18:34 SQL> select * from emp versions between
timestamp sysdate- 15 /(24*60) and sysdate
where empno=7902;