--运行于归档模式且打开闪回日志的数据库,可以进行任意方向的闪回(向回或向前)
--查看数据库运行在归档模式
sys@TESTDB11>archiveloglist;
DatabaselogmodeArchiveMode
Automatic archivalEnabled
Archive destination/archive2
Oldestonlinelogsequence97
Nextlogsequencetoarchive99
Currentlogsequence99
--开启闪回日志
sys@TESTDB11>alterdatabase
flashbackon;
Database altered.
--创建表
scott@TESTDB11>createtableemp1asselect*fromemp;
Tablecreated.
--创建还原点并删除数据
scott@TESTDB11>createrestore
point rp_bd_analyst;
Restore point created.
--删除analyst
scott@TESTDB11>deletefromemp1wherejob='ANALYST';
2rowsdeleted.
--删除clerk
scott@TESTDB11>createrestore
point rp_bd_clerk;
Restore point created.
scott@TESTDB11>deletefromemp1wherejob='CLERK';
4rowsdeleted.
--删除manager
scott@TESTDB11>createrestore
point rp_bd_manager;
Restore point created.
scott@TESTDB11>deletefromemp1wherejob='MANAGER';
3rowsdeleted.
--删除president
scott@TESTDB11>createrestore
point rp_bd_president;
Restore point created.
scott@TESTDB11>deletefromemp1wherejob='PRESIDENT';
1rowdeleted.
sys@TESTDB11>shutdownimmediate;
idle>startup mount;
ORACLE instance started.
Total SystemGlobalArea855982080bytes
FixedSize2230792bytes
VariableSize645924344bytes
Database Buffers205520896bytes
Redo Buffers2306048bytes
Database mounted.
--闪回到第2个还原点
idle>flashback databasetorestore point rp_bd_clerk;
Flashback complete.
idle>alterdatabaseopenreadonly;
Database altered.
idle>conn scott/scott
Connected.
scott@TESTDB11>select*fromemp1;
EMPNO ENAMEJOBMGR HIREDATESALCOMMDEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369SMITHCLERK790217-DEC-8080020
7499ALLENSALESMAN769820-FEB-81160030030
7521WARDSALESMAN769822-FEB-81125050030
7566JONESMANAGER783902-APR-81297520
7654MARTINSALESMAN769828-SEP-811250140030
7698BLAKEMANAGER783901-MAY-81285030
7782CLARKMANAGER783909-JUN-81245010
7839KINGPRESIDENT17-NOV-81500010
7844TURNERSALESMAN769808-SEP-811500030
7876ADAMSCLERK778823-MAY-87110020
7900JAMESCLERK769803-DEC-8195030
7934MILLERCLERK778223-JAN-82130010
12rowsselected.
scott@TESTDB11>select*fromemp1orderbyjob;
EMPNO ENAMEJOBMGR HIREDATESALCOMMDEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7934MILLERCLERK778223-JAN-82130010
7900JAMESCLERK769803-DEC-8195030
7876ADAMSCLERK778823-MAY-87110020
7369SMITHCLERK790217-DEC-8080020
7566JONESMANAGER783902-APR-81297520
7698BLAKEMANAGER783901-MAY-81285030
7782CLARKMANAGER783909-JUN-81245010
7839KINGPRESIDENT17-NOV-81500010
7844TURNERSALESMAN769808-SEP-811500030
7521WARDSALESMAN769822-FEB-81125050030
7499ALLENSALESMAN769820-FEB-81160030030
7654MARTINSALESMAN769828-SEP-811250140030
12rowsselected.
scott@TESTDB11>conn/assysdba
Connected.
sys@TESTDB11>shutdownimmediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@TESTDB11>startup mount;
ORACLE instance started.
Total SystemGlobalArea855982080bytes
FixedSize2230792bytes
VariableSize645924344bytes
Database Buffers205520896bytes
Redo Buffers2306048bytes
Database mounted.
--闪回到第1个还原点
sys@TESTDB11>flashback databasetorestore point rp_bd_analyst;
Flashback complete.
sys@TESTDB11>alterdatabaseopenreadonly;
Database altered.
sys@TESTDB11>select*fromscott.emp1orderbyjob;
EMPNO ENAMEJOBMGR HIREDATESALCOMMDEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7788SCOTT ANALYST756619-APR-87300020
7902FORDANALYST756603-DEC-81300020
7934MILLERCLERK778223-JAN-82130010
7900JAMESCLERK769803-DEC-8195030
7369SMITHCLERK790217-DEC-8080020
7876ADAMSCLERK778823-MAY-87110020
7698BLAKEMANAGER783901-MAY-81285030
7566JONESMANAGER783902-APR-81297520
7782CLARKMANAGER783909-JUN-81245010
7839KINGPRESIDENT17-NOV-81500010
7844TURNERSALESMAN769808-SEP-811500030
7654MARTINSALESMAN769828-SEP-811250140030
7521WARDSALESMAN769822-FEB-81125050030
7499ALLENSALESMAN769820-FEB-81160030030
14rowsselected.
sys@TESTDB11>shutdownimmediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@TESTDB11>startup mount;
ORACLE instance started.
Total SystemGlobalArea855982080bytes
FixedSize2230792bytes
VariableSize645924344bytes
Database Buffers205520896bytes
Redo Buffers2306048bytes
Database mounted.
--闪回到第4个还原点
sys@TESTDB11>flashback databasetorestore point rp_bd_president;
Flashback complete.
sys@TESTDB11>alterdatabaseopenreadonly;
Database altered.
sys@TESTDB11>select*fromscott.emp1orderbyjob;
EMPNO ENAMEJOBMGR HIREDATESALCOMMDEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7839KINGPRESIDENT17-NOV-81500010
7521WARDSALESMAN769822-FEB-81125050030
7844TURNERSALESMAN769808-SEP-811500030
7499ALLENSALESMAN769820-FEB-81160030030
7654MARTINSALESMAN769828-SEP-811250140030
sys@TESTDB11>shutdownimmediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@TESTDB11>startup mount;
ORACLE instance started.
Total SystemGlobalArea855982080bytes
FixedSize2230792bytes
VariableSize645924344bytes
Database Buffers205520896bytes
Redo Buffers2306048bytes
Database mounted.
--闪回到第3个还原点
sys@TESTDB11>flashback databasetorestore point rp_bd_manager;
Flashback complete.
sys@TESTDB11>alterdatabaseopenreadonly;
Database altered.
sys@TESTDB11>select*fromscott.emp1orderbyjob;
EMPNO ENAMEJOBMGR HIREDATESALCOMMDEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7782CLARKMANAGER783909-JUN-81245010
7698BLAKEMANAGER783901-MAY-81285030
7566JONESMANAGER783902-APR-81297520
7839KINGPRESIDENT17-NOV-81500010
7844TURNERSALESMAN769808-SEP-811500030
7521WARDSALESMAN769822-FEB-81125050030
7499ALLENSALESMAN769820-FEB-81160030030
7654MARTINSALESMAN769828-SEP-811250140030
8rowsselected.
sys@TESTDB11>shutdownimmediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
--恢复到第4个还原点
sys@TESTDB11>startup mount;
ORACLE instance started.
Total SystemGlobalArea855982080bytes
FixedSize2230792bytes
VariableSize645924344bytes
Database Buffers205520896bytes
Redo Buffers2306048bytes
Database mounted.
--在rman中执行recover
RMAN>recover databasetorestore point rp_bd_president;
Starting recoverat25-FEB-14
usingtarget database controlfileinsteadofrecoverycatalog
allocated channel:ORA_DISK_1
channel ORA_DISK_1:SID=21devicetype=DISK
starting media recovery
media recovery complete,elapsedtime:00:00:01
Finished recoverat25-FEB-14
sys@TESTDB11>alterdatabaseopenreadonly;
Database altered.
sys@TESTDB11>select*fromscott.emp1orderbyjob;
EMPNO ENAMEJOBMGR HIREDATESALCOMMDEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7839KINGPRESIDENT17-NOV-81500010
7521WARDSALESMAN769822-FEB-81125050030
7844TURNERSALESMAN769808-SEP-811500030
7499ALLENSALESMAN769820-FEB-81160030030
7654MARTINSALESMAN769828-SEP-811250140030
--结论:可以向回,也可以向前来回进行闪回操作.向前闪回等价于recover操作