Professional Documents
Culture Documents
Starting on Oracle 11g, its possible to keep every transaction made to the table and keep it as long as you want. Before 11g, in order to get a before
image of any row, either we were getting it from archived redo log files (if they are kept) using Log Miner, or by writing a trigger to save the data in
another log table.
But now, using Flashback Data Archive feature, a 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 cant 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:
-- Create flashback archive on this tablespace using CREATE FLASHBACK ARCHIVE command as follows:
create flashback archive fl_archive tablespace tbs_arch retention 1 year;
With above command weve 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:
create table tbl_fl_archive (id number, name varchar2(20));
insert into tbl_fl_archive values(1,'Flashback Archive');
commit;
select * from tbl_fl_archive;
ID NAME
---------- -------------------1 Flashback Archive
alter table tbl_fl_archive flashback archive fl_archive;
The historical change on the table TBL_FL_ARCHIVE is now will be written to the flashback archive named FL_ARCHIVE.
Does your business need professional PDFs in your application or on your website? Try the PDFmyURL API!
-- 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
select to_char(sysdate,'ddmmyyyy hh24:mi:ss') ddate from dual;
DDATE
----------------13022010 12:46:49
delete from tbl_fl_archive;
commit;
select * from tbl_fl_archive;
no rows selected
select * from tbl_fl_archive as of timestamp to_timestamp('13022010 12:46:49','ddmmyyyy hh24:mi:ss');
ID NAME
---------- -------------------1 Flashback Archive
You should know that this feature doesn't look to the UNDO tablespace for the historical information on the rows for the specific time.
Flashback Features in Oracle 11g
Flashback Queries
Flashback Row and Transaction History
Flashback Transaction Backout
Flashback Table
Flashback Drop
Flashback Database
Flashback Data Archive
Flashback Queries
Principal uses of flashback query :
- Repair bad data
- Collect and review recent data values over time
To query a table:
Does your business need professional PDFs in your application or on your website? Try the PDFmyURL API!
Returns the salary for each transaction affecting the row, as follows:
EMPNO
----7766
7766
7766
SAL
---8000
7120
6300
ST
-----------------01-MAY-08 05.32.38
01-MAY-08 05.28.45
01-MAY-08 05.26.14
XID
----------------06001F0014170000
04002C00151B0000
0200290017370000
Does your business need professional PDFs in your application or on your website? Try the PDFmyURL API!
ename VARCHAR2(16) ,
sal number);
XID
START_SCN END_SCN
O ENAME SAL
EMPNO
---------------- --------- --------- - ------ ----- -----Does your business need professional PDFs in your application or on your website? Try the PDFmyURL API!
05002500BE000000
05001800BE000000
05001800BE000000
04001600BE000000
04001600BE000000
04001600BE000000
428380
428372
428372
428365
428365
428365
U
428380 U
D
I
428372 I
428372 I
BROWN
BROWN
GREEN
WHITE
BROWN
GREEN
6650
6000
4000
1000
3000
4000
8888
8888
7950
1111
8888
7950
Record current SCN at time of flashback if a reversal of the operation is required. This is found in v$database.current_scn or via
dbms_flashback.get_system_change_number
2. Perform the flashback table operation
FLASHBACK TABLE t1 TO SCN 12345;
or
FLASHBACK TABLE t1 TO TIMESTAMP TO_TIMESTAMP('2008-12-01 12:05:00') ENABLE TRIGGERS;
Triggers are not enabled by default during a flashback operation
On executing FLASHBACK TABLE, a global temporary table called sys_temp_fbt is created in the user schema, the rows are inserted using
INSERT APPEND. The rows are removed when session is terminated but the table is not dropped
The sys_temp_fbt tracks ROWIDs of affected rows:
Name
-------------SCHEMA
OBJECT_NAME
OBJECT#
RID
ACTION
Type
-----------VARCHAR2(32)
VARCHAR2(32)
NUMBER
ROWID
CHAR(1)
If you are curious, you can get the metadata for sys_temp_fbt:
RECYCLEBIN;
TABLESPACE user1;
TABLESPACE user1 USER fred;
INDEX "BIN$FTX34MN88J7==$0;
--Users with SYSDBA privilege, can purge the entire recycle bin
PURGE DBA_RECYCLEBIN;
A specific version can also be restored, If same table is dropped more than once, each dropped version is given a different bin name
FLASHBACK TABLE BIN$xyWe0+q+SniItJ0pn/u54A==$ TO BEFORE DROP;
You can use RENAME to avoid name clashes with new objects of the same name
FLASHBACK TABLE emp TO BEFORE DROP RENAME TO employees;
Flashback Database
Fast (point in time) recovery from recent logical errors
Effectively a rollback of the database
An alternative to normal recovery mechanisms
Setting up Flashback Database
1.Configure the recovery area by setting the following dynamic parameters
DB_RECOVERY_FILE_DEST
Does your business need professional PDFs in your application or on your website? Try the PDFmyURL API!
DATABASE
DATABASE
DATABASE
DATABASE
TO
TO
TO
TO
TIMESTAMP ...
BEFORE TIMESTAMP ...
BEFORE SCN ...
SCN ...
The Recovery Area is designed to hold flashback logs, archive logs, backupsets and image (datafile) copies. You should size it to keep enough
flashback to comply with the retention period. An alert is raised when Recovery Area is 85% full and the files are deleted when 100% full. The
chosen files to be deleted can be obsolete backups or flashback logs
Recovery Manager (RMAN) automatically deletes flashback logs in preference to other files needed for backup purposes. It's recommended not to
use FRA in a non-RMAN environment.
Useful Views
Use v$flashback_database_log to show
Available recovery window
Actual size of flashback data
An estimate of amount of flashback needed to support retention target
Use v$recovery_file_dest to show the total space usage in recovery area
SELECT name, space_limit, space_used, reclaimable_space reclaim, number_of_files files
FROM v$recovery_file_dest;
NAME
SPACE_LIMIT SPACE_USED RECLAIM FILES
----------------------------- ----------- ---------- ------- ----D:\oracle\flash_recovery_area 2147483648 364353536
0
86
estimated_flashback_size is the value found in v$flashback_database_log at the end of the time interval
Flashback Database Features
* Cannot recover from media failure such as loss of a datafile
* Cannot flashback past a shrink datafile
But can handle datafile automatic expansion
* Required flashback logs must be available
* Can also be used in a Data Guard environment
Used with snapshot standby databases
* Flashback data requires a lot of space
On Windows, logs are ~ 8MB on a quiet system with names like O1_MF_0B87CPH6_.FLB
Any change within a block means the whole block is logged
Flashback must be performed in a mount state and requires an :
ALTER DATABASE OPEN RESETLOGS;
But what happens if you are not sure that your flashback is to the correct point in time?
1- Open the database in READ ONLY mode to observe the data
ALTER DATABASE OPEN READ ONLY;
2- Shutdown
3- Mount the database
4- Flashback to a different point
Restore Points
These are named markers for FLASHBACK DATABASE, and avoids the need for SCNs or timestamps.
You can use it to "mark" a position before potentially risky operations that could compromise the database.
Can be normal or guaranteed, Normal restores require FLASHBACK mode. Guaranteed restores can be used when database not in FLASHBACK
mode
CREATE RESTORE POINT before_upgrade
[GUARANTEE FLASHBACK DATABASE];
Does your business need professional PDFs in your application or on your website? Try the PDFmyURL API!
CREATE TABLESPACE TBS_FBA1 DATAFILE 'c:\oracle\oradata\orcl\TBS_FBA1.dbf' SIZE 10G SEGMENT SPACE MANAGEMENT AUTO;
Create a FB Archive
or
(Optional) Allow a user to track changes to his tables in the fba1 archive
GRANT FLASHBACK ARCHIVE ON fb1 TO fred;
Does your business need professional PDFs in your application or on your website? Try the PDFmyURL API!
or
or
Does your business need professional PDFs in your application or on your website? Try the PDFmyURL API!
or
ALTER FLASHBACK ARCHIVE FB1 PURGE BEFORE TIMESTAMP(SYSTIMESTAMP INTERVAL '1' DAY);
-- To change tablespace quota of the tablespace that is used by a flashback data archive, use:
alter flashback archive fl_archive add tablespace tbs_arch quota 50m;
Does your business need professional PDFs in your application or on your website? Try the PDFmyURL API!
-- To purge the data thats in Flashback Data Archive, use PURGE BEFORE SCN (TIMESTAMP) or PURGE ALL as follows:
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:
The second view is DBA_FLASHBACK_ARCHIVE_TS which gives information about tablespace that contains flashback data archives:
select * from dba_flashback_archive_ts;
FLASHBACK_ARCHIVE_NAME
FLASHBACK_ARCHIVE#
--------------------------------------FL_ARCH
2
TABLESPACE_NAME
--------------TBS_ARCH
QUOTA_IN_MB
---------FL_ARC
The third view is FLASHBACK_ARCHIVE_TABLES which displays the information of the tables that uses Flashback Data Archive:
select * from dba_flashback_archive_tables;
TABLE_NAME
OWNER_NAME FLASHBACK_ARCHIVE_NAME
-------------- ---------- ---------------------TBL_FL_ARCHIVE US1
FL_ARC
ARCHIVE_TABLE_NAME
-----------------SYS_FBA_HIST_69845
Does your business need professional PDFs in your application or on your website? Try the PDFmyURL API!
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 thats used to store the data and query USER_TAB_PARTITIONS view as follows:
select table_name,tablespace_name from user_tables;
TABLE_NAME
TABLESPACE_NAME
------------------------------ -----------------------------SYS_FBA_HIST_69845
SYS_FBA_TCRV_69845
TBS_ARCH
SYS_FBA_DDL_COLMAP_69845
TBS_ARCH
TBL_FL_ARCHIVE
USERS
Does your business need professional PDFs in your application or on your website? Try the PDFmyURL API!