Oracle Consulting Oracle Training Oracle Support Development
Home
Catalog
Oracle Books
SQL Server Books
IT Books
Job Interview Books
eBooks
Rampant Horse Books
911 Series
Pedagogue Books

Oracle Software
image
image
Write for Rampant
Publish with Rampant
Rampant News
Rampant Authors
Rampant Staff
  Phone
  252-431-0050
Oracle News
Oracle Forum
Oracle Tips
Articles by our Authors
Press Releases
SQL Server Books
image
image

Oracle 11g Books

Oracle tuning

Oracle training

Oracle support

Remote Oracle

STATSPACK Viewer

    Privacy Policy

 

 
 

Oracle Flashback Data Archive (Total Recall)

Expert Oracle Tips by Kamran Agayev A.

July 21, 2010

 

By Kamran Agayev A.

Starting from Oracle 11g version, it’s possible to keep every transaction made to the table and keep it as long as you want. Before 11g, in order to get before image of any row, either we were getting it from archived redo log files (if they are kept) using Log Miner, or were writing a trigger to save the data in another log table. But now, using Flashback Data Archive feature, we don’t need to use Log Miner or trigger to track changes made to the table. The new background process, FBDA (Flashback Data Archive) tracks all changes made to the table and stores it in a file in a compressed and partitioned format. However, you can’t use this feature with clustered, temporary, nested, remote or external tables and LONG or nested columns

It tracks all transactional changes made to specific tables for the specific time interval. To use Flashback Data Archive feature the user needs to have the FLASHBACK ARCHIVE ADMINISTER system privilege. Moreover, the FLASHBACK ARCHIVE object privilege should be granted to the user to enable historical data tracking. In the following scenario we show you the configuration and usage of this feature in detailed examples:

Create a new user and grant him the required privileges:

1 SQL> create user usr identified by usr;
2  
3 User created.
4  
5 SQL> grant connect, resource, flashback archive administer to usr;
6  
7 Grant succeeded.
8  
9 SQL>  

Create a new separate tablespace for data archive

1 SQL> CREATE TABLESPACE tbs_arch DATAFILE 'c:\flashback_archive.dbf' size 10m;
2  
3 Tablespace created.
4  
5 SQL>

Create flashback archive on this tablespace using CREATE FLASHBACK ARCHIVE command as follows:

1 SQL> create flashback archive fl_archive
2  
3   2  tablespace tbs_arch retention 1 year;
4  
5 Flashback archive created.
6  
7 SQL>

With above command we’ve created a Flashback Archive named FL_ARCHIVE which resides in the tablespace TBS_ARCH and holds information for 1 year. It means that we can use any Flashback Query which contains 1 year historical information regarding the table that assigned to this flashback archive

Now, create a table, insert one row and assign it to this flashback archive:

01 SQL> create table tbl_fl_archive (id number, name varchar2(20));
02  
03 Table created.
04  
05 SQL> insert into tbl_fl_archive values(1,'Flashback Archive');
06  
07 1 row created.
08  
09 SQL> commit;
10  
11 Commit complete.
12  
13 SQL> select * from tbl_fl_archive;
14  
15         ID NAME
16  
17 ---------- --------------------
18  
19          1 Flashback Archive
20  
21 SQL> alter table tbl_fl_archive flashback archive fl_archive;
22  
23 Table altered.
24  
25 SQL>

The historical change on the table TBL_FL_ARCHIVE is now will be written to the flashback archive named FL_ARCHIVE.

To test it, delete all rows and use Flashback Query on that table. Remember, it will not look for the UNDO data, it will look to the flashback archive file for the changes

01 SQL> select to_char(sysdate,'ddmmyyyy hh24:mi:ss') ddate from dual;
02  
03 DDATE
04  
05 -----------------
06  
07 13022010 12:46:49
08  
09 SQL> delete from tbl_fl_archive;
10  
11 1 row deleted.
12  
13 SQL> commit;
14  
15 Commit complete.
16  
17 SQL> select * from tbl_fl_archive;
18  
19 no rows selected
20  
21 SQL> select * from tbl_fl_archive as of timestamp to_timestamp('13022010 12:46:49','ddmmyyyy hh24:mi:ss');
22  
23         ID NAME
24  
25 ---------- --------------------
26  
27          1 Flashback Archive
28  
29 SQL>  

In order to show and proof that it doesn’t look to the UNDO tablespace for the historical information on the rows for the specific time, create new undo tablespace and make it default by dropping the old one. Then use Flashback Versions on that table:

01 SQL> conn / as sysdba
02  
03 Connected.
04  
05 SQL> show parameter undo_tablespace;
06  
07 NAME                                 TYPE        VALUE
08  
09 --------------------- -----------    ---------   ------------
10  
11 undo_tablespace                      string      UNDOTBS1
12  
13 SQL> select a.name from v$datafile a, v$tablespace b where a.ts#=b.ts# and b.name='UNDOTBS1';
14  
15 NAME
16  
17 ------------------------------------------------
18  
19 C:\APP\ADMINISTRATOR\ORADATA\DB2\UNDOTBS01.DBF
20  
21 SQL> create undo tablespace undotbs2 datafile 'C:\APP\ADMINISTRATOR\ORADATA\DB2\UNDOTBS02.dbf' size 10m;
22  
23 Tablespace created.
24  
25 SQL> alter system set undo_tablespace='UNDOTBS2';
26  
27 System altered.
28  
29 SQL> startup force
30  
31 ORACLE instance started.
32  
33 Total System Global Area  431038464 bytes
34  
35 Fixed Size                  1333676 bytes
36  
37 Variable Size             251659860 bytes
38  
39 Database Buffers          171966464 bytes
40  
41 Redo Buffers                6078464 bytes
42  
43 Database mounted.
44  
45 Database opened.
46  
47 SQL> show parameter undo_tablespace;
48  
49 NAME                                 TYPE        VALUE
50  
51 ---------------------------              ----------- ------------
52  
53 undo_tablespace                      string      UNDOTBS2

As you see, we’re currently using the different UNDO tablespace that hasn’t any information about before images of data blocks of the TBL_FL_ARCHIVE. Now, let’s use Flashback Query against to that table:

01 SQL> conn us1/us1
02  
03 Connected.
04  
05 SQL> select * from tbl_fl_archive as of timestamp to_timestamp('13022010 12:45:30','ddmmyyyy hh24:mi:ss');
06  
07         ID NAME
08  
09 ---------- --------------------
10  
11          1 Flashback Archive
12  
13 SQL>  

This query gets the data from Flashback Data Archive

Modify the Flashback Data Archive  

Use ALTER FLASHBACK ARCHIVE command to change the retention time, purge data or add or remove the tablespace. For this you need to have FLASHBACK ARCHIVE ADMINISTER privilege granted.  

To change the retention time, use:

1 SQL> alter flashback archive fl_archive modify retention 6 month;
2  
3 Flashback archive altered.
4  
5 SQL>

To change tablespace quota of the tablespace that is used by a flashback data archive, use:

1 SQL> alter flashback archive fl_archive add tablespace tbs_arch quota 50m;
2  
3 Flashback archive altered.
4  
5 SQL>

To add another tablespace for flashback data archive, use:

1 SQL> create tablespace tbs_arch2 datafile 'c:\flashback_archive2.dbf' size 10m;
2  
3 Tablespace created.
4  
5 SQL> alter flashback archive fl_archive add tablespace tbs_arch2 quota 10m;
6  
7 Flashback archive altered.
8  
9 SQL>

To remove the tablespace from use by flashback data archive, use:

1 SQL> alter flashback archive fl_archive remove tablespace tbs_arch2;
2  
3 Flashback archive altered.
4  
5 SQL>

To purge the data that’s in Flashback Data Archive, use PURGE BEFORE SCN (TIMESTAMP) or PURGE ALL as follows:

01 SQL> ALTER FLASHBACK ARCHIVE fl_archive PURGE ALL;
02  
03 Flashback archive altered.
04  
05 SQL> ALTER FLASHBACK ARCHIVE fl_archive purge before timestamp to_timestamp('13022010 12:49:30','ddmmyyyy hh24:mi:ss');
06  
07 Flashback archive altered.
08  
09 SQL> ALTER FLASHBACK ARCHIVE fl_archive purge before scn 988827;
10  
11 Flashback archive altered.
12  
13 SQL>

Dropping Flashback Data Archive  

To drop flashback data archive use:

1 SQL> drop flashback archive fl_archive;
2  
3 Flashback archive dropped.
4  
5 SQL>

Using default Flashback Data Archive for the system  

As default, Oracle doesn’t use any flashback data archive. To set default flashback data archive, use the following command by connecting as SYS user:

1 SQL> conn / as sysdba
2  
3 Connected.
4  
5 SQL> alter flashback archive fl_arc set default;
6  
7 Flashback archive altered.
8  
9 SQL>

By setting default flashback data archive, you will not need to specify it manually on each table you want to keep changes

To disable flashback archive for a table, use:  

1 SQL> alter table tbl_fl_archive no flashback archive;
2  
3 Table altered.
4  
5 SQL>

Query Flashback Data Archive  

There’re mainly three views that are used to query the information regarding Flashback Data Archive.

The first view is DBA_FLASHBACK_ARCHIVE which gives information about Flashback Data Archive files

01 SQL> select * from dba_flashback_archive;
02  
03 FLASHBACK_ARCHIVE_NAME FLASHBACK_ARCHIVE# RETENTION_IN_DAYS CREATE_TIME
04  
05 LAST_PURGE_TIME     
06  
07 ---------------      --------------             ------------  ----------
08  
09 FL_ARCH                       2                 365           13-FEB-10
10  
11 08.05.14.000000000 PM                    13-FEB-10 08.05.14.000000000 PM  

The second view is DBA_FLASHBACK_ARCHIVE_TS which gives information about tablespace that contains flashback data archives:

1 SQL> select * from dba_flashback_archive_ts;
2  
3 FLASHBACK_ARCHIVE_NAME       FLASHBACK_ARCHIVE#  TABLESPACE_NAME QUOTA_IN_MB
4  
5 ------------------     -----------------   -------------    ----------
6  
7 FL_ARCH                        2                TBS_ARCH        FL_ARC

The third view is FLASHBACK_ARCHIVE_TABLES which displays the information of the tables that uses Flashback Data Archive:

1 SQL> select * from dba_flashback_archive_tables;
2  
3 TABLE_NAME    OWNER_NAME    FLASHBACK_ARCHIVE_NAME   ARCHIVE_TABLE_NAME
4  
5 ----------    ----------    ----------------------   ------------------
6  
7 TBL_FL_ARCHIVE  US1        FL_ARC               SYS_FBA_HIST_69845

As it was told above, Flashback Data Archie technology stores data in Compressed and Partitioned format. It should be checked easily. Get the name of the main table that’s used to store the data and query USER_TAB_PARTITIONS view as follows:

01 SQL> select table_name,tablespace_name from user_tables;
02  
03 TABLE_NAME                     TABLESPACE_NAME
04  
05 ------------------------------ ------------------------------
06  
07 SYS_FBA_HIST_69845
08  
09 SYS_FBA_TCRV_69845             TBS_ARCH
10  
11 SYS_FBA_DDL_COLMAP_69845       TBS_ARCH
12  
13 TBL_FL_ARCHIVE                 USERS
14  
15 SQL> select table_name, partition_name, compression, compress_for from user_tab_partitions where table_name='SYS_FBA_HIST_69845';
16  
17 TABLE_NAME                     PARTITION_NAME                 COMPRESS
18  
19 ----------------           --------------                 ---------
20  
21 SYS_FBA_HIST_69845             HIGH_PART                      ENABLED 
22  
23 SQL>

 
 
 
Get the Complete
Oracle Tuning Details 

The landmark book "Oracle Tuning: The Definitive Reference Second Edition" has been updated with over 1,150 pages of expert performance tuning tips. It's packed with scripts and tools to hypercharge Oracle 11g performance and you can buy it for 40% off directly from the publisher.
 


Download your Oracle scripts now:

www.oracle-script.com

The definitive Oracle Script collection for every Oracle professional DBA

 

 
   

 Copyright © 1996 -2011 by Burleson Enterprises. All rights reserved.


Oracle® is the registered trademark of Oracle Corporation. SQL Server® is the registered trademark of Microsoft Corporation. 
Many of the designations used by computer vendors to distinguish their products are claimed as Trademarks
 

 

Linux Oracle commands syntax poster

ION Oracle tuning software

Oracle data dictionary reference poster



Oracle Forum

BC Oracle consulting support training

BC remote Oracle DBA