Wednesday, August 5, 2009

How to Enable Flashback Database

1)Configure the Database in archivelog mode.

A)See the current archiving mode of the database.
SQL>select log_mode from v$database;

B)Perform clean shutdown of the database.
shutdown immediate or,
shutdown transactional or,
shutdown normal
You cannot change the mode from ARCHIVELOG to NOARCHIVELOG if any datafiles need media recovery.

C)Backup the Database.

D)If you use pfile as initialization file then edit the archive destination parameter (like LOG_ARCHIVE_DEST) as your archival destination. If you use spfile ignore this step.

E)Mount the database but don't open.
STARTUP MOUNT

F)Change the archival mode and open the database.

ALTER DATABASE ARCHIVELOG
If you use spfile then you can use ALTER SYSTEM SET LOG_ARCHIVE_DEST='your location'
ALTER DATABASE OPEN;


G)Check the archival Location
archive log list

H)Shutdown and Backup the database.
SHUTDOWN IMMEDIATE




2)Configure Flash Recovery Area.

A)Set up DB_RECOVERY_FILE_DEST_SIZE:
SQL> alter system set db_recovery_file_dest_size=2G;

B)Decide the area from OS where you will place Flash recovery area.
SQL>host mkdir /oradata1/flash_recovery_area

C)Set up DB_RECOVERY_FILE_DEST:
SQL> alter system set db_recovery_file_dest='/oradata1/flash_recovery_area';

3)Shutdown and mount the database.
SQL>SHUTDOWN IMMEDIAT;
SQL>STARTUP MOUNT:
SQL>Alter Database Flashback ON;
SQL> select flashback_on from v$database;

4)Open the database and optionally you can set DB_FLASHBACK_RETENTION_TARGET to
the length of the desired flashback window in minutes.

SQL> ALTER DATABASE OPEN;
SQL> ALTER SYSTEM SET DB_FLASHBACK_RETENTION_TARGET=4320;
SQL> show parameter DB_FLASHBACK_RETENTION_TARGET;
NOTE:
The V$RECOVERY_FILE_DEST and V$FLASH_RECOVERY_AREA_USAGE views can help to find out the current location, disk quota, space in use, space reclaimable by deleting files,total number of files, the percentage of the total disk quota used by different types of files, and how much space for each type of file can be reclaimed by deleting files that are obsolete, redundant, or already backed up to tape.

In order to disable flash recovery area issue,
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST='' SCOPE=BOTH SID="*";

However you can disable Flashback Database for a tablespace.Then you must take its datafiles offline before running FLASHBACK DATABASE.

Like,

SQL> select file_name,file_id from dba_data_files where tablespace_name='TEST';
FILE_NAME FILE_ID
------------------------------ ----------
/oradata2/1.dbf 5

SQL> alter database datafile 5 offline;
Database altered.

SQL> ALTER TABLESPACE test flashback off;
Tablespace altered.

SQL> recover datafile 5;
Media recovery complete.

SQL> alter database datafile 5 online;
Database altered.

To disable flashback feature simply issue,
SQL>ALTER DATABASE FLASHBACK OFF;
Database altered.

Mohammad Abdul Momin Arju