FLASHBACK TECHNOLOGY EXAMPLES IN 10g.pdf

July 20, 2017 | Author: G.R.THIYAGU ; Oracle DBA | Category: Oracle Database, Database Transaction, Databases, Database Index, Table (Database)
Share Embed Donate


Short Description

Download FLASHBACK TECHNOLOGY EXAMPLES IN 10g.pdf...

Description

FLASHBACK TECHNOLOGY IN ORACLE 10g

ORACLE FLASHBACK TECHNOLOGY Oracle flashback having group of features that provide ways to view past states of database objects , or to return database objects to a previous state. The flashback process is fast, because no need to restore the backups. The purpose of flash back is quickly recover from logical corruptions or user errors. Flashback features of the Oracle database can be used to , Recover tables or rows to a previous point in time. Perform queries that return past data & perform queries that return metadata that shows a detailed history of changes to the database. Flashback Technology use the Automatic Undo Management (AUM) system to obtain metadata and historical data for transactions. They rely on undo data. Flashback does

NOT

work on the ‘SYSTEM’ Tablespace. If we connect to

oracle as SYS (by default system tablespace) create a table , drop it , & then try to flashback it , it will fail. Flashback works on the

NON - SYSTEM

tablespace.

Flashback database uses the Flashback Logs and is controlled by the Flashback Retention target and default value for flashback retention time is 1400 mins. SQL> show parameter db_flashback_retention_target ; DB_FLASHBACK_RETENTION_TARGET is to keep how long oracle would

keep the flashback logs in the flash recovery area (FRA) i.e. ( the period of time which we want to retain flashback logs). Flashback features are primarily for data recovery and typically used for DATABASE ADMINS. Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

FLASHBACK LEVELS FLASHBACK LEVELS

ROW LEVEL

flashback query, flashback versions query, flashback transaction query

TABLE LEVEL

flashback table, flashback drop

DATABASE LEVEL flashback database

NEW FLASHBACK FEATURES IN 10g

Flashback Technology gives following different ways to track and fix data corruption.  Flashback database  Flashback drop  Flashback table  Flashback query  Flashback Version query  Flashback Transaction query Two flashback technologies that do NOT use the undo data, but using flashback logs and recyclebin. Flashback database & Flashback drop.  Flashback database uses the flashback logs.  Flashback drop uses the recycle bin. APPLICATION DEVELOPMENT features are ,

(Flashback query , Flashback version query , Flashback Transaction query). DATABASE ADMINISTRATION features are ,

( Oracle Flashback table , Oracle Flashback drop , Oracle Flashback database). Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

ORACLE FLASHBACK QUERY FLASHBACK QUERY retrieves data from a past at a particular time.

Oracle flashback query allows a user to view the data as it existed at a particular time in the past (even though the data is committed or modified). The query explicitly references a past time through a TIMESTAMP or SCN.

 Ensure the database is using ‘undo tablespace ’.  undo_management should be ‘auto’.

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

FLASHBACK QUERY WITH AS OF CLAUSE

We can use a flashback AS OF query to get back the deleted rows. Using AS OF clause for recovering data to a certain point in time. Flashback queries

can be used in two ways. ( TIMEBASED BASED & SCN BASED ) .

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

EXAMPLE 01 : SCN number can be obtained before the transaction is initiated by using

the GET_SYSTEM_CHANGE_NUMBER function of the DBMS_FLASHBACK utility. SQL> select dbms_flashback. get_system_change_number from dual ;

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g EXAMPLE 02 :

As we can query from a table as it was existed in the past. This feature does not need to set up FLASHBACK area. Recovered deleted data. Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

FLASHBACK VERSION QUERY FLASHBACK VERSION QUERY to retrieve metadata & historical data for a

specific time interval (whether the rows were inserted, deleted, or updated) between two SCNs or time stamps. Even a row was deleted and reinserted , all changes are available with this feature and this feature (FVQ) does NOT need any special setup in the database and based on UNDO tablespace. Oracle Flashback Version Query is using the VERSIONS BETWEEN clause of the SELECT statement. The versions of a specific row to be tracked at a particular time period using the versions between clause. It takes 2 forms as VERSIONS BETWEEN SCN - [ lower bound ] - [ upper bound ]. VERSIONS BETWEEN TIMESTAMP - [ lower bound ] - [ upper bound ] ;

VERSIONS BETWEEN SCN 670678 AND 670718

VERSIONS BETWEEN TIMESTAMP TO_TIMESTAMP('09-MAY-14 19:45:33’, 'DD-MON-YY HH24:MI:SS') AND TO_TIMESTAMP('09-MAY-14 19:52:18', 'DD-MON-YY

HH24:MI:SS')

The lower and upper boundaries can either be specific timestamps/SCNs. One restriction with using specific timestamps or SCNs is that they must be within the boundaries of the undo_retention parameter. Because The age of the data available is determined by the undo_retention parameter. Attempting to flashback undo_retention will result as ‘ORA-30052’ - invalid lower limit snapshot expression.

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

POINTS TO NOTE

Whenever we want to use of any of the flashback feature , undo_ retention increased to higher value. Metadata for each row version includes start and end time, type of change operation, and identity of the transaction that created the row version. Each row in the table includes pseudo columns of metadata about the row version. The pseudo columns are given below.

PSUEDO COLUMN

DESCRIPTION

VERSIONS_XID

Transaction ID of the transaction that created this version.

VERSIONS_OPERATION

Operation Performed . I  Insert , U  Update , D  Delete.

VERSIONS_STARTSCN

SCN of the first version

VERSIONS_STARTTIME

Timestamp of the first version

VERSIONS_ENDSCN

SCN of the last version

VERSIONS_ENDTIME

Timestamp of the last version

FVQ (SCN).txt

FVQ (TMSTMP).txt

FVQ _TMSTMP1.txt

SOME LIMITATIONS & RESTRICTIONS ON FLASHBACK QUERY

Flashback Query does NOT tell what changed. It is NOT available after restarting the database. Flashback Query does NOT work through DDL operations that modify columns, or drop or truncate tables. It does NOT undo anything , Just like a query mechanism. We can take the output from a Flashback Query and perform an undo operation. Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

FLASHBACK TRANSACTION QUERY

The Flashback Transaction Query is used to view the changes made to the database at the transaction level. Oracle provides the data dictionary view FLASHBACK_TRANSACTION_QUERY – This feature (FTQ) queries this view , a

user can determine what changes were made by a specific transaction (or) what changes were made during a specific time. Using this method to we can get The UNDO SQL and no need to use LOG MINER. To get “undo” sql statement, we need to know Transaction ID (XID)

value, i.e. The VERSIONS_XID column values from a flashback version query can be used to query the flashback_transaction_query view. .

The UNDO_SQL generated by the flashback_ transaction_query and it can be used to rollback the changes made by a transaction.

FTQ.txt

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

Using UNDO_SQL statement from the INSERT OPERATION , I am trying to delete a record from the table tab1.

POINTS TO NOTE

Oracle data dictionary view FLASHBACK_TRANSACTION_QUERY to retrieve transaction information. This view provides the SQL statements that we can use to undo the changes made by a particular transaction. Flashback Transaction Query drills down history of table changes based on Transaction ID. Using Flashback Versions Query, we can find out which transaction has changed but we can’t find who made the change. Flashback Transaction Query provides (logon_user) so, we can find who has changed. ORACLE FLASHBACK QUERY , ORACLE FLASHBACK VERSION QUERY , ORACLE FLASHBACK TRANSACTION QUERY these are application development features. ORACLE FLASHBACK TABLE , ORACLE FLASHBACK DROP , ORACLE FLASHBACK DATABASE these are database administration features.

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

ORACLE FLASHBACK TABLE

Flashback table related features are Flashback table & Flashback drop. Oracle Provides Flashback Table feature the DBA having the ability to simply revert a table to previous point in time i.e. (Recover a table or set of tables to a specified point in time (past)). To flash back a table, user should need to an earlier SCN or TIMESTAMP. Flashback table uses information in the undo tablespace to restore the table. We can only flash back tables up to the retention time (undo_retention). Flashback oracle database cannot restore a table to an earlier state across any DDL operations that change the structure of the table.

Before performing the FLASHBACK TABLE

operation, row movement

should be enabled on the table . SQL> ALTER TABLE ENABLE ROW MOVEMENT ;

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

POINTS TO NOTE :

Row movement must be enabled on the table, which indicates that rowids will change after the flashback occurs. This restriction exists because if rowids before the flashback were stored by the application, then there is no guarantee that the rowids will correspond to the same rows after the flashback. If your application depends on rowids, then we cannot use Flashback Table.

FLASHBACK TAB.txt

Now the table is restored to its state when the database was at the time specified by the timestamp. During the flashback table operation , Oracle is created a temporary table. Table can be identified as SYS_TEMP_FBT.

FLASHBACK TABLE RESTRICTIONS

FB RESTRICT.txt

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

DDL operations change the structure of a table, we cannot subsequently use

the TO SCN or TO TIMESTAMP clause to flash the table back to a time. Ex : Adding a constraint , modifying or dropping a column , truncate a table , etc.. Flashback table which relies on undo segments and Flashback drop which relies on the recyclebin not the undo segments.

FLASHBACK DROP FLASHBACK DROP feature provides a way to restore accidentally dropped

tables. This feature is available even after restarting the database. Dropped objects must NOT be created in SYSTEM tablespace. To know flashback drop, first need to be clarified the " recycle bin " . RECYCLE BIN

When a user drops a table , oracle renames the table to a system identifiable string (starts with

BIN$) ,

it is placed in recycle bin. Users can query the recycle

bin. We cannot use DML or DDL statements on objects in the recycle bin.

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

DROP TABLE FROM THE RECYCLEBIN

Dropped table tab1 do not actually get deleted. Oracle just renames the table i.e. System-generated name that begins with BIN$. SQL> Purge table tab1

We can enable & disable the recycle bin with the recyclebin initialization parameter at system level or session level. It is enabled by default in 10g.

When the recycle bin is enabled, dropped tables and their dependent objects are placed in the recycle bin. When it is disabled, dropped tables & their dependent objects are not placed in the recycle bin. Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

DROP TABLE COMPLETELY

Who wants to drop the table permanently, use purge option. (dropped table will not be in the recycle bin). SQL> drop table purge ; SQL> drop table tab4 purge ;

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

FLASHBACK DROP EXAMPLES

FB_DROP.txt

As a DBA, we do not need to setup anything in the database for flashback drop. What I say , this is one of the best features of Flashback Technology. LIMITATIONS ON FLASHBACK DROP

We cannot flash back a table if it has been purged. When we drop a table, materialized view logs defined on the table are also dropped but are not placed in the recycle bin. Therefore, the materialized view logs cannot be flashed back along with the table. If a table had referential constraints before it was dropped (that is, placed in the recycle bin), then re-create any referential constraints after retrieve the table from the recycle bin with Flashback drop. When we drop a table with indexes, in this case , If subsequent space pressures arise, then the database reclaims space from the recycle bin by first purging indexes. In this case when we flash back the table, may not get back all of the indexes that were defined on the table. After doing flashback table, the restored constraints and index will have the same (system generated name - recyclebin names). While it was dropped and saved in the recycle bin. We need to explicitly rename the indexes and constraints to proper names. index & cons rename.txt

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

FLASHBACK DATABASE

The Flashback database feature allows , DBA brings the entire database back to a specific point -in time - that means going back to a previous database state. This feature provides a way to quickly revert an entire Oracle database to the past state (past point in time). Oracle provides quickly recover database to a previous time to correct problems caused by logical data corruptions or user errors. Flashback can fix logical failures, but not physical failures. DBA cannot use the command to recover accidental deletion of datafiles. This feature is good replacement for incomplete recovery of full database. This is faster than traditional point-in-time recovery. FLASHBACK LOGS

The Flashback database is not based on undo data but on flashback logs. If flashback database is enabled , it’s flashback logs are stored in the Flash Recovery area. Flashback database is implemented using a new type of log file called Flashback database logs. The oracle database server periodically receives (logs) before images of data blocks in the flashback database logs. (Data block images are used to quickly backing out changes to the datafiles during flashaback database). When flashback database is enabled , a new RVWR background process is started. This process is similar to the LGWR process. The new process writes Flashback database data to the Flashback database logs. Flashback database reduces the time required to recover the database to a previous point.

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

DATABASE

L G W R

LGWR

RVWR

R V W R

FLASHBACK DATABASE LOGS

REDO LOG FILES

When enabled flashback on , a new background process RVWR is started. $ ps –ef | grep orcl  ‘orcl ‘ is instance name. DB_FLASHBACK_RETENTION_TARGET 

This parameter value determines

how far back into the past want to be able to restore the database i.e. how much the flashback data, the database retains. This value is in minutes. The default value for DB_FLASHBACK_RETENTION_TARGET is 1440 which is 24 hours. SQL > alter system set DB_FLASHBACK_RETENTION_TARGET = 10080; Once set these parameter, from that time, image copies of each altered block, in every datafile into flashback logs stored in the flash recovery area. These Flashback logs are used to flashback database to a point in time. Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

HOW MUCH SIZE DBA SHOULD SET TO THE FRA

The V$FLASHBACK_DATABASE_LOG view can help to estimate how much space to add to flash recovery area for flashback logs. SQL> select estimated_flashback_size from v$flashback_database_log; HOW FAR DBA CAN FLASHBACK THE DATABASE.

To determine the earliest SCN & TIME , to Flashback the database, SQL> select oldest_flashback_scn , oldest_flashback_time from v$flashback_database_log ; CONFIGURE FLASH RECOVERY AREA:

The Flash Recovery Area is defined by two initialization parameters. They are DB_RECOVERY_FILE_DEST_SIZE & DB_RECOVERY_FILE_DEST. DB_RECOVERY_FILE_DIST_SIZE  specifies the size of the FRA and must be

set before DB_RECOVERY_FILE_DEST. DB_RECOVERY_FILE_DEST  displays information about the disk and current

disk usage in the flash recovery area.

FRA CONFIG.txt

In order to flashback the database we must have SYSDBA privilege and the flash recovery area must have been configured in advance. We can’t revert back the database to a time more than db_flashback_retention_target value. The DBA need to estimate the size of the FRA, and allocate disk storage. Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

FLASHBACK TECHNOLOGY IN ORACLE 10g

FLASHBACK DATABASE OPERATION ( POINT IN TIME RECOVERY )

Flashback the database to undo the changes made. We can perform the flashback in either SQL*Plus or RMAN. ( examples given below).

FB DATABASE.txt

FB DB (rman).txt

POINTS TO NOTE

The database must be in ARCHIVELOG mode in order to enable Flashback database. Configure the FLASH RECOVERY AREA. The Flashback database logs are stored in the Flash Recovery Area and are automatically created and managed when Flashback database is enabled. The Flash Recovery Area (FRA) is defined by two initialization parameters. DB_RECOVERY_FILE_DEST_SIZE & DB_RECOVERY_FILE_DEST.

The parameter DB_FLASHBACK_RETENTION_TARGET specifies, in minutes, how far you want to be able to flashback the database. To enable flashback database use the ALTER DATABASE FLASHBACK ON command in mount phase. The database must be mounted and not open in order to perform the flashback database operation. We can perform the flashback database operation in either SQL*Plus or RMAN. Database need to be open with the RESETLOGS option. Now the database is back in their original state.

Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF