Flashback technology in oracle 11 g


Published on

Describe all technologies in Flashback.

Published in: Self Improvement
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Flashback technology in oracle 11 g

  1. 1. FLASHBACK TECHNOLOGY IN ORACLE DATABASE 11g Written By: Ahmer Mansoor Email : ahmer_mansoor@hotmail.com Profile : http://www.linkedin.com/in/ahmermansoor
  2. 2. Written By: Ahmer MansoorEmail : ahmer_mansoor@hotmail.comProfile : http://www.linkedin.com/in/ahmermansoor Main application of Flashback Technologies is to point out logical errors and undo erroneouschanges without performing point in time recovery. There are various technologies that come underFlashback Umbrella. Each one of them is discussed and demonstrated in this tutorial. First of all, set the Undo Retention to 1 Hour and Retention Guarantee to avoid lower limiterrors. SQL> ALTER SYSTEM SET UNDO_RETENTION=3600 SCOPE=SPFILE; SQL> ALTER TABLESPACE UNDOTBS1 RETENTION GUARANTEE; SQL> SHUTDOWN IMMEDIATE; SQL> STARTUP; Page | 2
  3. 3. Written By: Ahmer MansoorEmail : ahmer_mansoor@hotmail.comProfile : http://www.linkedin.com/in/ahmermansoor1) Flashback Drop It is used to Undrop dropped tables. Uses LIFO method while Undrop and after undrop the table is renamed to original while its relevant indexes, triggers etc. still have the system generated names and cannot be revert to original names automatically. System Parameter RECYCLEBIN must be ON to use Flashhback Drop (Default is ON). SQL> ALTER SYSTEM SET RECYCLEBIN=ON SCOPE=SPFILE; (Hint: Set RECYCLEBIN=OFF to disable Flashback Drop.) To query what objects can be undrop: SQL> SELECT * FROM RECYCLEBIN; To undrop a table, use any of the following Commands: SQL> FLASHBACK TABLE HR.DEPARTMENTS TO BEFORE DROP; OR SQL> FLASHBACK TABLE HR.EMPLOYEES TO BEFORE DROP RENAME TO EMP1; To Empty Recyclebin: SQL> PURGE RECYCLEBIN; To bypass recylebin while deleting a Table: SQL> DROP TABLE T1 PURGE; Page | 3
  4. 4. Written By: Ahmer MansoorEmail : ahmer_mansoor@hotmail.comProfile : http://www.linkedin.com/in/ahmermansoor2) Flashback Query Use to view data at a specific point in time. Uses Undo data, hence the greater the UNDO_RETENTION parameter the more historical data can be queried. Moreover, a Flashback Data Archive can be created to retain undo data for comparatively longer periods to support more historical Flashback queries (i.e 1 year or before). SQL> SELECT * FROM HR.EMPLOYEES > AS OF TIMESTAMP > TO_TIMESTAMP(‘2011-MAY-25 14:35:30’,’YYYY-MON-DD HH24:MI:SS’) > WHERE EMPLOYEE_ID=200; OR SQL> SELECT * FROM HR.EMPLOYEES > AS OF SCN 1067856 > WHERE EMPLOYEE_ID=200; Page | 4
  5. 5. Written By: Ahmer MansoorEmail : ahmer_mansoor@hotmail.comProfile : http://www.linkedin.com/in/ahmermansoor3) Flashback Version Query See all versions of rows between two times/SCN and the transaction that changes the row. Like Flashback Query it also depends on UNDO DATA. SQL> SELECT VERSIONS_XID,FIRST_NAME > FROM HR.EMPLOYEES > VERSIONS BETWEEN TIMESTAMP > TO_TIMESTAMP(2011-MAY-30 01:20:00,YYYY-MON-DD HH24:MI:SS) > AND > TO_TIMESTAMP(2011-MAY-30 01:50:00,YYYY-MON-DD HH24:MI:SS); OR SQL> SELECT VERSIONS_XID, FIRST_NAME FROM HR.EMPLOYEES > VERSIONS BETWEEN SCN > 1067855 AND 1067857; Page | 5
  6. 6. Written By: Ahmer MansoorEmail : ahmer_mansoor@hotmail.comProfile : http://www.linkedin.com/in/ahmermansoor4) Flashback Transaction Query See all changes made by a transaction. An UNDO_SQL for each statement executed within the transaction is available in FLASHBACK_TRANSACTION_QUERY table to revert back the changes (FLASHBACK LOGS must be enabled to obtain UNDO_SQL from FLASHBACK_TRANSACTION_QUERY table). Also uses UNDO DATA. Enable Flashback Logs: SQL> ALTER SYSTEM > SET DB_FLASHBACK_RETENTION_TARGET=2880 SCOPE=BOTH; SQL> SHUTDOWN IMMEDIATE; SQL> STARTUP MOUNT; SQL> ALTER DATABASE FLASHBACK ON; SQL> ALTER DATABASE OPEN; Grant the necessary Privilege to user to query FLASHBACK_TRANSACTION_QUERY: SQL> GRANT SELECT ANY TRANSACTION TO HR; Use following command to query transactions: SQL> SELECT XID,TABLE_NAME,UNDO_SQL FROM > FLASHBACK_TRANSACTION_QUERY > WHERE XID=HEXTORAW(07000A0082020000); The value in HEXTORAW() is the versions_xid obtained with Flashback Version Query. (Hint: Copy/paste and execute the UNDO_SQL to revert the effect of a single statement.) Page | 6
  7. 7. Written By: Ahmer MansoorEmail : ahmer_mansoor@hotmail.comProfile : http://www.linkedin.com/in/ahmermansoor5) Flashback Transaction With Flashback Transaction, you can reverse a transaction and dependent transactions. Uses the DBMS_FLASHBACK package to back-out a transaction. Enable Supplemental Logging: SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA; SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS; Grant necessary Privileges to User: SQL> GRANT EXECUTE ON DBMS_FLASHBACK TO HR; SQL> GRANT SELECT ANY TRANSACTION TO HR; Back-out a Transaction: SQL> EXEC DBMS_FLASHBACK.TRANSACTION_BACKOUT(NUMTXNS=>1, XIDS=>SYS.XID_ARRAY(07000A0082020000)); (Hint: Use DESC DBMS_FLASHBACK to see all procedures & their parameters) One of following options can be specified to fine tune back-out operations. NOCASCADE: Default. Backs out specified transactions, which are expected to have no dependent transactions. CASCADE : Backs out specified transactions and all dependent transactions in a post- order fashion (that is, children are backed out before parents are backed out). NOCASCADE_FORCE: Backs out specified transactions, ignoring dependent transactions. Server executes undo SQL statements for specified transactions in reverse order of commit times. NONCONFLICT_ONLY: Backs out changes to no conflicting rows of the specified transactions. Database remains consistent, but transaction atomicity is lost. Page | 7
  8. 8. Written By: Ahmer MansoorEmail : ahmer_mansoor@hotmail.comProfile : http://www.linkedin.com/in/ahmermansoor6) Flashback Table Use to recover tables to specific point in time. Requires Undo Data and Row Movement must be enabled for the respective table. Grant Flashback Any Table Privilege to User: SQL> GRANT FLASHBACK ANY TABLE TO HR; Enable Row Movement: SQL> ALTER TABLE DEPARTMENTS ENABLE ROW MOVEMENT; Flashback table using any of following commands: SQL> FLASHBACK TABLE DEPARTMENTS TO TIMESTAMP > TO_TIMESTAMP(2011-MAY-30 01:40:00,YYYY-MON-DD HH24:MI:SS); OR SQL> FLASHBACK TABLE TO SCN 1067855; Page | 8
  9. 9. Written By: Ahmer MansoorEmail : ahmer_mansoor@hotmail.comProfile : http://www.linkedin.com/in/ahmermansoor7) Flashback Database Rewinds database. Uses Flashback Logs to perform operations. Enable Flashback Logs as already mentioned in 4) above. Flashback Database by using any of the following commands: SQL> FLASHBACK DATABASE TO TIMESTAMP (SYSDATE-1/24); OR SQL> FLASHBACK DATABASE TO SCN 1067855; OR SQL> FLASHBACK DATABASE TO RESTORE POINT B4_LOAD; OR SQL> FLASHBACK DATABASE TO BEFORE RESETLOGS; Database must be opened with RESETLOGS after flashback database. Page | 9
  10. 10. Written By: Ahmer MansoorEmail : ahmer_mansoor@hotmail.comProfile : http://www.linkedin.com/in/ahmermansoor8) Flashback Data Archive Create Archiving of Undo Data and retain it for longer periods like 1 year or more. It is also refer to as Total Recall. Create a Tablespace for Data Archive. SQL> CREATE TABLESPACE TBS1 > DATAFILE D:APPADMINISTRATORORADATAPRODTBS01.DBF > SIZE 500M AUTOEXTEND ON; Create Flashback Data Archive. SQL> CREATE FLASHBACK ARCHIVE DEFAULT FLA1 > TABLESPACE TBS1 QUOTA 10G RETENTION 5 YEAR; Add Tables to Flashback Archive. SQL> ALTER TABLE HR.EMPLOYEES FLASHBACK ARCHIVE; SQL> ALTER TABLE HR.DEPARTMENTS FLASHBACK ARCHIVE; Now undo data of at most 5 years will be retained for the above tables. Page | 10
  11. 11. Written By: Ahmer MansoorEmail : ahmer_mansoor@hotmail.comProfile : http://www.linkedin.com/in/ahmermansoor9) Guaranteed Restore Point No need to enable Flashback Logs for Flashback database to a guaranteed restore point. It stores all the required undo data and logs required to flashback database to specific restore point. Create Guaranteed Restore Point by using following command. SQL> CREATE RESTORE POINT B4_LOAD > GUARANTEE FLASHBACK DATABASE; Page | 11