ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback...

14
ORACLE FLASHBACK

Transcript of ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback...

Page 1: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

ORACLEFLASHBACK

Page 2: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

Flashback

• Flashback a nivel de base de datos• Flashback a nivel de tabla• Flashback a nivel de tabla borrada• Flashback query• Flashback query versions• Flashback transaction query

Page 3: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

Flashback Query

• Oracle Flashback Query allows users to see a consistent view of the database as it was at a point in the past. This functionality allows comparative reporting over time and recovery from logical corruptions.

Page 4: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

How does the flashback query work?

• The Oracle database uses a version based read consistency mechanism by saving an image of the data prior to making any modifications.

• These changes are stored in the undo tablespace (or Rollback Segments).

• Should the user later decide not to commit the transaction or if the operation was not successful, Oracle uses thedata saved in the undo tablespace to recreate the original data

Page 5: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

How does the flashback query work?

• The undo data is also used to generate a snapshot of data consistent to a point in time when a query was started if another user has modified the underlying data.

• Flashback Query relies on the same mechanism to construct an image of the data as it existed at a time in the past.

• The undo data, therefore, must be available in order for a Flashback Query to be successful.

Page 6: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

How does the flashback query work?

• Oracle9i’s Automatic Undo Management feature allows administrators to specify how long they wish to retain the undo data using the UNDO_RETENTION initialization parameter.

• By using this parameter and sizing the undo tablespace appropriately, DBAs can control how far back a Flashback Query can go.

Page 7: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

PRE-REQUISITES

• Oracle Flashback Query can only be used if the server is configured to use Automatic Undo Management, rather than traditional rollback segments. The maximum time period that can be flashbacked to is defined using the UNDO_RETENTION parameter in the init.ora file. Alternatively, this parameter can be set using:

• Alter system set undo_management=auto scope=spfile; • ALTER SYSTEM SET UNDO_RETENTION = <seconds>;• GRANT FLASHBACK ANY TABLE TO USER;

Page 8: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

FLASHBACK QUERY

• Enable the undo_retention• Grant privileges FLASHBACK ANY TABLE• Select * from SCHEMA.TABLE AS OF TIMESTAMP

TO_TIMESTAMP(‘DD-MM-YYYY HH:MM:SS');• Select * from SCHEMA.TABLE AS OF SCN (#);

• EXECUTE Dbms_Flashback.Enable_At_System_Change_Number(123);EXECUTE Dbms_Flashback.Enable_At_Time('28-AUG-01 11:00:00');

• EXECUTE Dbms_Flashback.Disable;

Page 9: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

Flashback Query Sample

• Alter System Set undo_retention = 1200; (sys)• Shutdown immediate• Startup• Creamos una copia de la tabla para efectuar el

ejemplo:• Create table Empleados as Select * from Emp; (scott)• Delete from Empleados Where Deptno = 10; (13-03-2009

11:16:04) 11:16:14 commit;

• Select * from SCOTT.EMPLEADOS AS OF TIMESTAMP TO_TIMESTAMP('13-03-2009 11:16:14')

Page 10: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

Flashback Query Sample ORACLE 9iR2

• Ver que datos no se encuentran o fueron borrados de la otra tabla:

• Select * from EMPLEADOS AS OF TIMESTAMP TO_TIMESTAMP('13-03-2009 11:16:14')MINUSSelect * from EMPLEADOS

• Restauramos la información en la tabla:• INSERT INTO EMPLEADOS

(Select * from EMPLEADOS AS OF TIMESTAMP TO_TIMESTAMP('13-03-2009 11:16:14')MINUSSelect * from EMPLEADOS)

Page 11: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

Flashback Query Sample ORACLE 9iR1

• Grant execute on dbms_flashback to scott;• 13:17:55 SQL> Delete from empleados where

deptno = 20;• 13:18:06 SQL> commit;• EXECUTE Dbms_Flashback.Enable_At_Time('13-

03-2009 01:18:06 PM')• Select * from Empleados;• Ejecutar Script• Deshabilitar Flashback• EXECUTE Dbms_Flashback.disable;

Page 12: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

Flashback Query Sample 9iR1

Page 13: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

Flashback Query Sample ORACLE 9iR1

• Para conocer el ultimo SCN:– DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER;

Page 14: ORACLE FLASHBACK. Flashback Flashback a nivel de base de datos Flashback a nivel de tabla Flashback a nivel de tabla borrada Flashback query Flashback.

Flashback Options ORACLE 10g

Flashback Version Query

Flashback Transaction Query