Вы находитесь на странице: 1из 28

Flashback Technologies Step by Step

Alejandro Vargas
Principal Support Consultant
Oracle Advanced Support Services


Flashback Database .............................................................................................................................................................................................. 2
Enabling Flashback Database............................................................................................................................................................................. 2
Flashback Database Options............................................................................................................................................................................... 4
Flashback Database Examples ........................................................................................................................................................................... 5
Flashback Table................................................................................................................................................................................................... 12
Enabling Flashback Table.................................................................................................................................................................................. 12
Flashback Table Examples................................................................................................................................................................................ 12
Flashback to SCN.......................................................................................................................................................................................... 12
Flashback Query Example............................................................................................................................................................................. 15
Flashback Transaction Query Example......................................................................................................................................................... 21
Flashback Drop.................................................................................................................................................................................................... 25
Enabling the Recycle Bin............................................................................................................................................................................... 25
Flashback to Before Drop.............................................................................................................................................................................. 25
Flashback to Before Drop with rename.......................................................................................................................................................... 27
References......................................................................................................................................................................................................... 28

Flashback Database

Flashback Database was introduced in 10g, it enables the possibility to revert the actual database to a previous point in time; and to do
this faster than with other available methods.

A new background process was introduced, the RVWR. It is responsible for writing flashback logs which stores pre-images of data
blocks.

Flashback Database is useful to restore the database in the event of logical data corruptions or human errors that invalidate large
amounts of data.

Flashback Database cannot be used in the case of media failure, in this case a database backup must be used.

To be able to use Flashback Database, archive log mode must be enabled and the last shutdown must have been a clean shutdown.

Enabling Flashback Database

To enable flashback database the following requirements need to be met:

Set flashback database on
Set the following parameters, they are dynamic and do not require shutdown

o DB_RECOVERY_FILE_DEST Flashback log location
o DB_RECOVERY_FILE_DEST_SIZE Max Flashback available space
o DB_FLASHBACK_RETENTION_TARGET Max time available to Flashback

Clean shutdown startup of the database is necessary in order to use Flashback Database.

SQL> shut down i mmedi at e;
Dat abase cl osed.
Dat abase di smount ed.
ORACLE i nst ance shut down.

SQL> st ar t up mount ;
ORACLE i nst ance st ar t ed.

Tot al Syst emGl obal Ar ea 167772160 byt es
Fi xed Si ze 1218316 byt es
Var i abl e Si ze 67111156 byt es
Dat abase Buf f er s 96468992 byt es
Redo Buf f er s 2973696 byt es
Dat abase mount ed.

SQL> Al t er dat abase f l ashback on;

Dat abase al t er ed.

SQL> show par amet er s f l ash

NAME TYPE VALUE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
db_f l ashback_r et ent i on_t ar get i nt eger 1440
SQL> show par amet er s r ecover

NAME TYPE VALUE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
db_r ecover y_f i l e_dest st r i ng / vmasmt est / f l ashr ecar ea
db_r ecover y_f i l e_dest _si ze bi g i nt eger 2G
r ecover y_par al l el i sm i nt eger 0

SQL> al t er dat abase open;

Dat abase al t er ed.

SQL> sel ect f l ashback_on f r omv$dat abase;

FLASHBACK_ON
- - - - - - - - - - - - - - - - - -
YES

Check the Flashback database processes on the Operating System prompt

I n t hi s ser ver t her e ar e t wo dat abases, bot h of t he have Fl ashback enabl ed.
I n t hi s exampl e I ' mwor ki ng wi t h dat abase r edf ox

{or acl e} / home/ or acl e [ vmr act est 1] > ps - ef a | gr ep or a_ | gr ep r vwr
or acl e 21984 1 0 Sep25 ? 00: 05: 42 or a_r vwr _whi t eowl
or acl e 12431 1 0 16: 02 ? 00: 00: 01 or a_r vwr _r edf ox

Flashback Database Options

Flashback Database can be implemented based on one of these three options:

SCN
Timestamp
Log Sequence Number

In all cases the database must be shutdown cleanly and then mounted.

Flashback Database Examples


In these examples we will check flashing back a database after running a small batch.


Check if automatical archival is enabled and if flashback logs are being generated

SQL> ar chi ve l og l i st
Dat abase l og mode Ar chi ve Mode
Aut omat i c ar chi val Enabl ed
Ar chi ve dest i nat i on USE_DB_RECOVERY_FI LE_DEST
Ol dest onl i ne l og sequence 1
Next l og sequence t o ar chi ve 2
Cur r ent l og sequence 2

SQL> show par amet er s db_r ecover y_f i l e_dest

NAME TYPE VALUE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
db_r ecover y_f i l e_dest st r i ng / vmasmt est / f l ashr ecar ea
db_r ecover y_f i l e_dest _si ze bi g i nt eger 2G


SQL> ! l s - l / vmasmt est / f l ashr ecar ea/ REDFOX/ f l ashback
t ot al 8020
- r w- r - - - - - 1 or acl e dba 8200192 Oct 8 16: 56 o1_mf _3j ng3yd4_. f l b


Check SCN and Timestamp and Log Sequences before running the batch

SQL>select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER
------------------------
479899

SQL>select sysdate from dual;

SYSDATE
--------------
08/10/07 16:54

SQL> sel ect SEQUENCE#, BYTES, ARCHI VED, STATUS, FI RST_TI ME f r om v$l og
2 /

SEQUENCE# BYTES ARC STATUS FI RST_TI ME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2 52428800 NO CURRENT 08/ 10/ 07 15: 58
0 52428800 YES UNUSED
1 52428800 YES I NACTI VE 08/ 10/ 07 15: 54


Execute the batch

. . .

292428 r ows cr eat ed.

Commi t compl et e.

584856 r ows cr eat ed. <<<<<< Cont r ol r ecor ds t o f l ashback

Commi t compl et e.

Check SCN and Timestamp and Log Sequences while running the batch

Initial SCN Next SCN
479899 481960

Initial Date Next Date
08/10/07 16:54 08/ 10/ 07 17: 15


Initial Sequences

SEQUENCE# BYTES ARC STATUS FI RST_TI ME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2 52428800 NO CURRENT 08/ 10/ 07 15: 58
0 52428800 YES UNUSED
1 52428800 YES I NACTI VE 08/ 10/ 07 15: 54

Next Sequences

SEQUENCE# BYTES ARC STATUS FI RST_TI ME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5 52428800 NO CURRENT 08/ 10/ 07 17: 14
3 52428800 YES I NACTI VE 08/ 10/ 07 17: 13
4 52428800 YES ACTI VE 08/ 10/ 07 17: 14

Continue the batch

cr eat e t abl e my2ndsour ce: Tabl e cr eat ed.

99 r ows cr eat ed.

Commi t compl et e.

1169712 r ows cr eat ed.

Commi t compl et e.

Check SCN and Timestamp and Log Sequences while running the batch

Initial SCN Next SCN Next SCN
479899 481960 482934

Initial Date Next Date Next Date
08/10/07 16:54 08/ 10/ 07 17: 15 08/ 10/ 07 17: 19

Initial Sequences

SEQUENCE# BYTES ARC STATUS FI RST_TI ME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2 52428800 NO CURRENT 08/ 10/ 07 15: 58
0 52428800 YES UNUSED
1 52428800 YES I NACTI VE 08/ 10/ 07 15: 54

Next Sequences

SEQUENCE# BYTES ARC STATUS FI RST_TI ME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5 52428800 NO CURRENT 08/ 10/ 07 17: 14
3 52428800 YES I NACTI VE 08/ 10/ 07 17: 13
4 52428800 YES ACTI VE 08/ 10/ 07 17: 14

Next Sequences

SEQUENCE# BYTES ARC STATUS FI RST_TI ME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 52428800 YES ACTI VE 08/ 10/ 07 17: 17
9 52428800 NO CURRENT 08/ 10/ 07 17: 17
7 52428800 YES ACTI VE 08/ 10/ 07 17: 17

Shutdown and Startup Mount the Database

SQL> conn / as sysdba
Connect ed.

SQL> shut down i mmedi at e;
Dat abase cl osed.
Dat abase di smount ed.
ORACLE i nst ance shut down.

SQL> st ar t up mount ;
ORACLE i nst ance st ar t ed.

Tot al Syst emGl obal Ar ea 167772160 byt es
Fi xed Si ze 1218316 byt es
Var i abl e Si ze 67111156 byt es
Dat abase Buf f er s 96468992 byt es
Redo Buf f er s 2973696 byt es
Dat abase mount ed.

Flashback Database Options

At t hi s poi nt we can use any of t hese commands t o f l ashback t he dat abase t o a pr evi ous poi nt i n t i me
I n t hi s exampl e we wi l l f l ashback pr i or t o t he cr eat e t abl e my2ndsour ce, so we can use any of :

SCN 481960
TI MESTAMP 08/ 10/ 07 17: 15
SEQUENCE 5

The commands can be:

f l ashback dat abase t o scn 481960;
f l ashback dat abase t o TI MESTAMP t o_dat e( ' 08/ 10/ 07 17: 15' , ' dd/ mm/ yy hh24: mi ' ) ;
f l ashback dat abase t o sequence=5 t hr ead=1;

Af t er t he f l ashback command open r eset l ogs must be used.

Flashback command

SQL> f l ashback dat abase t o TI MESTAMP t o_dat e( ' 08/ 10/ 07 17: 15' , ' dd/ mm/ yy hh24: mi ' ) ;

Fl ashback compl et e.

On the alert log we see

Mon Oct 8 17: 54: 14 2007
f l ashback dat abase t o TI MESTAMP t o_dat e( ' 08/ 10/ 07 17: 15' , ' dd/ mm/ yy hh24: mi ' )
Mon Oct 8 17: 54: 15 2007
Fl ashback Rest or e St ar t
Fl ashback Rest or e Compl et e
Fl ashback Medi a Recover y St ar t
Fl ashback Medi a Recover y Log
/ vmasmt est / f l ashr ecar ea/ REDFOX/ ar chi vel og/ 2007_10_08/ o1_mf _1_2_3j nl 8wd7_. ar c
Fl ashback Medi a Recover y Log
/ vmasmt est / f l ashr ecar ea/ REDFOX/ ar chi vel og/ 2007_10_08/ o1_mf _1_3_3j nl 9t gz_. ar c
Mon Oct 8 17: 54: 34 2007
Fl ashback Medi a Recover y Log
/ vmasmt est / f l ashr ecar ea/ REDFOX/ ar chi vel og/ 2007_10_08/ o1_mf _1_4_3j nl bkpz_. ar c
Fl ashback Medi a Recover y Log
/ vmasmt est / f l ashr ecar ea/ REDFOX/ ar chi vel og/ 2007_10_08/ o1_mf _1_5_3j nl j 2mb_. ar c
Mon Oct 8 17: 54: 47 2007
I ncompl et e Recover y appl i ed unt i l change 481950
Fl ashback Medi a Recover y Compl et e
Compl et ed: f l ashback dat abase t o TI MESTAMP t o_dat e( ' 08/ 10/ 07 17: 15' , ' dd/ mm/ yy hh24: mi ' )

Open the database with resetlogs option

SQL> al t er dat abase open r eset l ogs;

Dat abase al t er ed.

Check the control table (584856 r ows cr eat ed. <<<<<< Cont r ol r ecor ds t o f l ashback)


SQL> sel ect count ( *) f r ommysour ce;

COUNT( *)
- - - - - - - - - -
584856

Flashback Table

Flashback Table enables recovery of tables to a point in time in the past.


Enabling Flashback Table

A table can be flashbacked to an earlier SCN or timestamp, the pre-requisites to be able to perform this operation are:

1. Flashback any table, or Flashback privilege on the table to be flashed back.
2. Select, Insert, Delete, and Alter object privileges on the table.
3. Row movement must be enabled for all tables in the Flashback list

Flashback Table Examples

Flashback to SCN

I n t hi s exampl e a t abl e i s i nser t ed a coupl e of t i mes checki ng t he syst emchange number ( SCN)
each t i me.
The t abl e i s f l ashbacked t o i t ' s or i gi nal ver si on, and t hen f l ashbacked agai n t o a l at er
ver si on. Fl ashback t abl e depends on undo r ecor ds and i f you have t he undo avai l abl e you can go
up and down i n t i me wi t hout pr obl em.

SQL> al t er t abl e user s enabl e r ow movement ;

Tabl e al t er ed.

SQL> sel ect count ( *) f r omuser s;

COUNT( *)
- - - - - - - - - -
25

SQL> sel ect dbms_f l ashback. get _syst em_change_number f r omdual ;

GET_SYSTEM_CHANGE_NUMBER
- - - - - - - - - - - - - - - - - - - - - - - -
2294900

SQL> i nser t i nt o user s sel ect * f r omuser s;

25 r ows cr eat ed.

SQL> commi t ;

Commi t compl et e.

SQL> sel ect dbms_f l ashback. get _syst em_change_number f r omdual ;

GET_SYSTEM_CHANGE_NUMBER
- - - - - - - - - - - - - - - - - - - - - - - -
2294911

SQL> i nser t i nt o user s sel ect * f r omuser s;

50 r ows cr eat ed.

SQL> commi t ;

Commi t compl et e.

SQL> sel ect dbms_f l ashback. get _syst em_change_number f r omdual ;

GET_SYSTEM_CHANGE_NUMBER
- - - - - - - - - - - - - - - - - - - - - - - -
2294917

SQL> sel ect count ( *) f r omuser s;

COUNT( *)
- - - - - - - - - -
100

SQL> f l ashback t abl e user s t o scn 2294900;

Fl ashback compl et e.

SQL> sel ect count ( *) f r omuser s;

COUNT( *)
- - - - - - - - - -
25

SQL> f l ashback t abl e user s t o scn 2294917;

Fl ashback compl et e.

SQL> sel ect count ( *) f r omuser s;

COUNT( *)
- - - - - - - - - -
100


Flashback Query Example

Fl ashback Quer y i s based on undo. I n t hi s exampl e a set of r ecor ds i s updat ed and t hen
r est or ed f r oma pr evi ous ver si on based on t he t i mest amp.

Two di f f er ent synt axes ar e shown t o get t o a t i mest amp:

As of TI MESTAMP ( SYSTI MESTAMP - I NTERVAL ' 5' MI NUTE)
As of TI MESTAMP t o_dat e( ' 08/ 10/ 07 11: 58' , ' dd/ mm/ yy hh24: mi ' )


SQL> sel ect USERNAME, ACCOUNT_STATUS f r omuser s
2 /

USERNAME ACCOUNT_STATUS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SYS OPEN
SYSTEM OPEN
DBSNMP OPEN
SI EBEL OPEN
CX_NUMBER_MGMT OPEN
SI EBEL_RO OPEN
AVARGAS OPEN
OUTLN EXPI RED & LOCKED
MGMT_VI EW EXPI RED & LOCKED
MDSYS EXPI RED & LOCKED
ORDSYS EXPI RED & LOCKED
EXFSYS EXPI RED & LOCKED
DMSYS EXPI RED & LOCKED
WMSYS EXPI RED & LOCKED
CTXSYS EXPI RED & LOCKED
ANONYMOUS EXPI RED & LOCKED
SYSMAN EXPI RED & LOCKED
XDB EXPI RED & LOCKED
ORDPLUGI NS EXPI RED & LOCKED
SI _I NFORMTN_SCHEMA EXPI RED & LOCKED
OLAPSYS EXPI RED & LOCKED
SCOTT EXPI RED & LOCKED
TSMSYS EXPI RED & LOCKED
MDDATA EXPI RED & LOCKED
DI P EXPI RED & LOCKED

25 r ows sel ect ed.

SQL> SELECT SYSDATE FROM DUAL;

SYSDATE
- - - - - - - - - - - - - -
08/ 10/ 07 11: 58

SQL> updat e user s set ACCOUNT_STATUS=' UNKNOWN' wher e ACCOUNT_STATUS l i ke ' EXPI RED%' ;

18 r ows updat ed.

SQL> commi t ;

Commi t compl et e.

SQL> sel ect USERNAME, ACCOUNT_STATUS f r omuser s wher e ACCOUNT_STATUS=' UNKNOWN' ;

USERNAME ACCOUNT_STATUS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OUTLN UNKNOWN
MGMT_VI EW UNKNOWN
MDSYS UNKNOWN
ORDSYS UNKNOWN
EXFSYS UNKNOWN
DMSYS UNKNOWN
WMSYS UNKNOWN
CTXSYS UNKNOWN
ANONYMOUS UNKNOWN
SYSMAN UNKNOWN
XDB UNKNOWN
ORDPLUGI NS UNKNOWN
SI _I NFORMTN_SCHEMA UNKNOWN
OLAPSYS UNKNOWN
SCOTT UNKNOWN
TSMSYS UNKNOWN
MDDATA UNKNOWN
DI P UNKNOWN

18 r ows sel ect ed.

Get back to the original values

SQL> SELECT USERNAME, ACCOUNT_STATUS f r omuser s
2 AS OF TI MESTAMP ( SYSTI MESTAMP - I NTERVAL ' 5' MI NUTE)
3 wher e ACCOUNT_STATUS l i ke ' EXPI RED %' ;

USERNAME ACCOUNT_STATUS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OUTLN EXPI RED & LOCKED
MGMT_VI EW EXPI RED & LOCKED
MDSYS EXPI RED & LOCKED
ORDSYS EXPI RED & LOCKED
EXFSYS EXPI RED & LOCKED
DMSYS EXPI RED & LOCKED
WMSYS EXPI RED & LOCKED
CTXSYS EXPI RED & LOCKED
ANONYMOUS EXPI RED & LOCKED
SYSMAN EXPI RED & LOCKED
XDB EXPI RED & LOCKED
ORDPLUGI NS EXPI RED & LOCKED
SI _I NFORMTN_SCHEMA EXPI RED & LOCKED
OLAPSYS EXPI RED & LOCKED
SCOTT EXPI RED & LOCKED
TSMSYS EXPI RED & LOCKED
MDDATA EXPI RED & LOCKED
DI P EXPI RED & LOCKED

18 r ows sel ect ed.

Compare old and new values

SQL> l
1 sel ect a. user name, a. ACCOUNT_STATUS, b. ACCOUNT_STATUS ACCOUNT_STATUS_OLD
2 f r omuser s a,
3 user s AS OF TI MESTAMP t o_dat e( ' 08/ 10/ 07 11: 58' , ' dd/ mm/ yy hh24: mi ' ) b
4* wher e a. user name=b. user name
SQL> /

USERNAME ACCOUNT_STATUS ACCOUNT_STATUS_OLD
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SYS OPEN OPEN
SYSTEM OPEN OPEN
DBSNMP OPEN OPEN
SI EBEL OPEN OPEN
CX_NUMBER_MGMT OPEN OPEN
SI EBEL_RO OPEN OPEN
AVARGAS OPEN OPEN
OUTLN UNKNOWN EXPI RED & LOCKED
MGMT_VI EW UNKNOWN EXPI RED & LOCKED
MDSYS UNKNOWN EXPI RED & LOCKED
ORDSYS UNKNOWN EXPI RED & LOCKED
EXFSYS UNKNOWN EXPI RED & LOCKED
DMSYS UNKNOWN EXPI RED & LOCKED
WMSYS UNKNOWN EXPI RED & LOCKED
CTXSYS UNKNOWN EXPI RED & LOCKED
ANONYMOUS UNKNOWN EXPI RED & LOCKED
SYSMAN UNKNOWN EXPI RED & LOCKED
XDB UNKNOWN EXPI RED & LOCKED
ORDPLUGI NS UNKNOWN EXPI RED & LOCKED
SI _I NFORMTN_SCHEMA UNKNOWN EXPI RED & LOCKED
OLAPSYS UNKNOWN EXPI RED & LOCKED
SCOTT UNKNOWN EXPI RED & LOCKED
TSMSYS UNKNOWN EXPI RED & LOCKED
MDDATA UNKNOWN EXPI RED & LOCKED
DI P UNKNOWN EXPI RED & LOCKED

25 r ows sel ect ed.

Create a view on the old version

cr eat e vi ew t mpv
as sel ect * f r omuser s
AS OF TI MESTAMP t o_dat e( ' 08/ 10/ 07 11: 58' , ' dd/ mm/ yy hh24: mi ' )
/

Update the table to restore old values

UPDATE user s
SET account _st at us = ( SELECT account _st at us
FROM t mpv
WHERE user s. user name = t mpv. user name)
WHERE EXI STS
( SELECT account _st at us
FROM t mpv
WHERE user s. user name = t mpv. user name)
/


SQL> l
1* sel ect user name, account _st at us f r omuser s
SQL> /

USERNAME ACCOUNT_STATUS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SYS OPEN
SYSTEM OPEN
DBSNMP OPEN
SI EBEL OPEN
CX_NUMBER_MGMT OPEN
SI EBEL_RO OPEN
AVARGAS OPEN
OUTLN EXPI RED & LOCKED
MGMT_VI EW EXPI RED & LOCKED
MDSYS EXPI RED & LOCKED
ORDSYS EXPI RED & LOCKED
EXFSYS EXPI RED & LOCKED
DMSYS EXPI RED & LOCKED
WMSYS EXPI RED & LOCKED
CTXSYS EXPI RED & LOCKED
ANONYMOUS EXPI RED & LOCKED
SYSMAN EXPI RED & LOCKED
XDB EXPI RED & LOCKED
ORDPLUGI NS EXPI RED & LOCKED
SI _I NFORMTN_SCHEMA EXPI RED & LOCKED
OLAPSYS EXPI RED & LOCKED
SCOTT EXPI RED & LOCKED
TSMSYS EXPI RED & LOCKED
MDDATA EXPI RED & LOCKED
DI P EXPI RED & LOCKED

25 r ows sel ect ed.


Flashback Transaction Query Example

Or acl e Fl ashback Tr ansact i on Quer y per mi t s t o vi ew changes made t o a t abl e by a si ngl e
t r ansact i on, or by al l t he t r ansact i ons dur i ng a per i od of t i me. You can quer y t he same r ow at
sever al poi nt i n t i me t o r evi ew t hei r di f f er ent ver si ons.

I t makes possi bl e t o per f or mr ecover y at t he Row Level .

For exampl e i t may hel p t o r est or e a r ow of dat a t hat was del et ed by er r or .

I n t hi s exampl e a r ow wi l l be del et ed and r est or ed usi ng t he pr evi ous i mage st i l l avai l abl e
f r omt he undo r ecor ds.

Get the SCN and actual time as references for the exercise

SQL> sel ect dbms_f l ashback. get _syst em_change_number f r omdual ;

GET_SYSTEM_CHANGE_NUMBER
- - - - - - - - - - - - - - - - - - - - - - - -
2302638

SQL> sel ect sysdat e f r omdual ;

SYSDATE
- - - - - - - - - - - - - -
08/ 10/ 07 14: 54

SQL> sel ect user name, account _st at us, cr eat ed f r omuser s
2 wher e user name=' AVARGAS' ;

USERNAME ACCOUNT_STATUS CREATED
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AVARGAS OPEN 02/ 04/ 07 09: 09

SQL> del et e f r omuser s wher e user name = ' AVARGAS' ;

1 r ow del et ed.

SQL> COMMI T;

Commi t compl et e.

Review the flashback records for the deleted row, two alternative syntaxes are shown.

sel ect user name, account _st at us, cr eat ed
f r omuser s
wher e user name=' AVARGAS' ;

no r ows sel ect ed

sel ect user name, account _st at us, cr eat ed
f r omuser s
as of SCN 2302638
wher e user name=' AVARGAS' ;

USERNAME ACCOUNT_STATUS CREATED
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AVARGAS OPEN 02/ 04/ 07 09: 09

sel ect user name, account _st at us, cr eat ed
f r omuser s
as of TI MESTAMP t o_dat e( ' 08/ 10/ 07 14: 54' , ' dd/ mm/ yy hh24: mi ' )
wher e user name=' AVARGAS' ;

USERNAME ACCOUNT_STATUS CREATED
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AVARGAS OPEN 02/ 04/ 07 09: 09

Restore the deleted row.

i nser t i nt o user s
sel ect * f r omuser s
as of TI MESTAMP t o_dat e( ' 08/ 10/ 07 14: 54' , ' dd/ mm/ yy hh24: mi ' )
wher e user name=' AVARGAS'
/

1 r ow cr eat ed.

commi t ;

Commi t compl et e.

sel ect user name, account _st at us, cr eat ed
f r omuser s
wher e user name=' AVARGAS'
/

USERNAME ACCOUNT_STATUS CREATED
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AVARGAS OPEN 02/ 04/ 07 09: 09


Flashback Drop

Fl ashback Dr op i s di f f er ent f r omFl ashback t abl e. I t uses t he r ecycl e bi n i nst ead of undo r ecor ds.
I t r est or es t he t abl e t o i t s st at e bef or e t he dr op. Row movement must be enabl ed i n or der t o be abl e
t o r est or e a t abl e f r omt he r ecycl e bi n.

Enabling the Recycle Bin


ALTER SYSTEM SET r ecycl ebi n = ON;

The Recycl e bi n can al so be enabl ed at t he sessi on l evel .

ALTER SESSI ON SET r ecycl ebi n = ON;

Flashback to Before Drop

A dr opped t abl e wi l l r emai n on t he r ecycl e bi n unt i l pur ged by t he user or over wr i t t en by
ot her r ecycl e bi n ent r i es, dr opped t abl es r ecover ed f r omt he r ecycl e bi n do not pr eser ve
r ef er ent i al i nt egr i t y const r ai nt s, i f t hey exi st ed t hey wi l l need t o be r ecr eat ed manual l y.

On t hi s exer ci se we dr op t he t abl e, t hen we r est or e i t by f l ashi ng back t o bef or e dr op, and
af t er t hat we f l ash back t o cer t ai n SCN, usi ng t he avai l abl e undo r ecor ds.

SQL> al t er t abl e user s enabl e r ow movement ;

Tabl e al t er ed.

SQL> dr op t abl e user s;

Tabl e dr opped.

SQL> sel ect count ( *) f r omuser s;
sel ect count ( *) f r omuser s
*
ERROR at l i ne 1:
ORA- 00942: t abl e or vi ew does not exi st

SQL> f l ashback t abl e user s t o bef or e dr op;

Fl ashback compl et e.

SQL> sel ect count ( *) f r omuser s;

COUNT( *)
- - - - - - - - - -
100

SQL> f l ashback t abl e user s t o scn 2294900;

Fl ashback compl et e.

SQL> sel ect count ( *) f r omuser s;

COUNT( *)
- - - - - - - - - -
25

Flashback to Before Drop with rename

On t hi s exer ci se we dr op t he t abl e, t hen we r est or e i t by f l ashi ng back t o bef or e dr op, and we
r ename i t , af t er t hat we f l ash back t o cer t ai n SCN, not e t hat despi t e t he new name t he r ecor ds
bel ongi ng t o t he t abl e user s ar e appl i ed.

SQL> dr op t abl e user s;

Tabl e dr opped.

SQL> sel ect obj ect _name, or i gi nal _name f r omuser _r ecycl ebi n;

OBJ ECT_NAME ORI GI NAL_NAME
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BI N$O/ est CI SH+7gQAQKTx5nsA==$0 USERS

SQL> f l ashback t abl e user s t o bef or e dr op r ename t o ol duser s;

Fl ashback compl et e.

SQL> sel ect obj ect _name, or i gi nal _name f r omuser _r ecycl ebi n;

no r ows sel ect ed

SQL> sel ect count ( *) f r omol duser s;

COUNT( *)
- - - - - - - - - -
25

SQL> f l ashback t abl e ol duser s t o scn 2294917;

Fl ashback compl et e.

SQL> sel ect count ( *) f r omol duser s;

COUNT( *)
- - - - - - - - - -
100


References

Metalink Notes:

Note 238674.1 - How to restore the old data using flashback queries?
Note 249319.1 - Configure flashback database
Note 270060.1 - Use Flashback Table Feature and Resolve errors
Note 270535.1 - Restrictions on Flashback Table Feature
Note 317499.1 - 10G Oracle Flashback Transaction Query - Introduction and usage
Note 369755.1 - Flashback Logs-Space management

Вам также может понравиться