例:
SQL> create table myemp as select * from emp
表建立.
SQL>
表刪除.
SQL> show recyclebin
ORIGINAL NAME
---------------- ------------------------------ ------------ -------------------
MYEMP
-----------------------閃回還原
SQL> flashback table myemp to before drop
閃回完成。
SQL> select empno ,ename ,job,sal deptno from myemp where deptno=20
2
3
4
5
6
7
8
9
10
SQL> drop table keep_scn;
Table dropped
SQL> flashback table keep_scn to before drop;
Done
SQL> drop table keep_scn;
Table dropped
改變恢復後的表名 rename to
SQL> flashback table keep_scn to before drop rename to keep_scnback;
Done
SQL >flashback database to time
to_date(xxx);
SQL >flashback database to time TO_TIMESTAMP
(xxx);
SQL >flashback database to scn xxx
SQL >flashback database to sequence xxx thread
1
SQL>flashback database to
timestamp(sysdate-1/24)
SQL>shutdown immediate;--立即關閉資料庫和例項
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
--啟動例項並載入資料庫
ORACLE instance started.
Total System Global
Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
Database mounted.
SQL> alter database flashback
on;--開啟閃回功能
alter database flashback on
*
ERROR at line 1:
ORA-38706: Cannot turn on FLASHBACK DATABASE logging.
ORA-38707: Media recovery is not enabled.
可以看到,flashback還必須要歸檔的保證
SQL> alter database
archivelog;--設為歸檔模式
Database altered.
SQL> alter database flashback on;
Database altered.
SQL> alter database open;--開啟資料庫
Database altered.
SQL> archive log list; --檢視當前模式
Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence
透過如下的查詢
SQL> alter session set nls_date_format='yyyy-mm-dd
hh24:mi:ss';
SQL> SELECT OLDEST_FLASHBACK_SCN,
OLDEST_FLASHBACK_TIME
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TI
-------------------- -------------------
SQL> create table t1 as select * from
dba_objects;
Table created.
SQL> create table t2 as select * from t1;
Table created.
SQL> create table t3 as select * from t1;
Table created.
SQL> set time on;
SQL> select sysdate from dual;
SYSDATE
-------------------
2008-05-17 15:29:33
SQL> set time on;
15:30:10 SQL> truncate table t2;
Table truncated.
15:30:43 SQL> drop table t3;
Table dropped.
15:39:02 SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
15:39:31 SQL> startup mount exclusive
ORACLE instance started.
15:41:19 SQL> FLASHBACK DATABASE TO
timestamp(to_date(2008-05-17 15:29:33','yyyy-mm-dd
hh24:mi:ss'));
Flashback complete.
15:41:32 SQL> alter database open resetlogs;
Database altered.
我們現在查詢那三個表
15:42:10 SQL> select count(*) from t1;
----------
15:42:47 SQL> select count(*) from t2;
----------
15:42:50 SQL> select count(*) from t3;
----------
15:44:56 SQL> SELECT OLDEST_FLASHBACK_SCN,
OLDEST_FLASHBACK_TIME FROM $FLASHBACK_DATABASE_LOG;
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TI
-------------------- -------------------
測試如下:
Microsoft Windows [版本 5.2.3790]
(C) 版權所有 1985-2003 Microsoft Corp.
C:Documents and SettingsAdministrator>sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 4月 2 16:53:38 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn sys as sysdba;
輸入口令:
已連線到空閒例程。
SQL> startup mount;
ORACLE 例程已經啟動。
Total System Global Area 293601280 bytes
Fixed Size 1248600 bytes
Variable Size 92275368 bytes
Database Buffers 192937984 bytes
Redo Buffers 7139328 bytes
資料庫裝載完畢。
SQL>
SQL>
SQL>
SQL> alter database flashback on;
資料庫已更改。
SQL> alter database open
2 ;
資料庫已更改。
SQL> set timing on;
SQL>
SQL>
SQL>
SQL> select 'ff' from dual;
'F
--
ff
已用時間: 00: 00: 00.00
SQL>
SQL>
SQL>
SQL> shutdown immediate;
資料庫已經關閉。
已經解除安裝資料庫。
ORACLE 例程已經關閉。
SQL> startup mount;
ORACLE 例程已經啟動。
Total System Global Area 293601280 bytes
Fixed Size 1248600 bytes
Variable Size 88081064 bytes
Database Buffers 197132288 bytes
Redo Buffers 7139328 bytes
資料庫裝載完畢。
SQL>
SQL> FLASHBACK DATABASE TO timestamp(to_date(2009-04-02 16:58:49','yyyy-mm-dd hh
24:mi:ss'));
ERROR:
ORA-01756: 引號內的字串沒有正確結束
已用時間: 00: 00: 00.00
SQL> FLASHBACK DATABASE TO timestamp(to_date('2009-04-02 16:58:49','yyyy-mm-dd
hh24:mi:ss'));
閃回完成。
已用時間: 00: 00: 08.14
SQL> alter database open resetlog;
alter database open resetlog
*
第 1 行出現錯誤:
ORA-02288: 無效的 OPEN 模式
已用時間: 00: 00: 00.01
SQL> alter database open resetlogs;
資料庫已更改。
已用時間: 00: 00: 48.68
SQL>
SQL>
SQL>
SQL> shutdown immediate;
資料庫已經關閉。
已經解除安裝資料庫。
ORACLE 例程已經關閉。
SQL>
SQL> startup mount;
ORACLE 例程已經啟動。
Total System Global Area 293601280 bytes
Fixed Size 1248600 bytes
Variable Size 92275368 bytes
Database Buffers 192937984 bytes
Redo Buffers 7139328 bytes
資料庫裝載完畢。
SQL>
SQL>
SQL> FLASHBACK DATABASE TO timestamp(to_date('2009-04-02 16:59:37','yyyy-mm-dd
hh24:mi:ss'));
閃回完成。
已用時間: 00: 00: 09.56
SQL> alter database open resetlogs;
資料庫已更改。
已用時間: 00: 00: 40.96
SQL> shutdown immediate;
資料庫已經關閉。
已經解除安裝資料庫。
ORACLE 例程已經關閉。
SQL>
SQL>
SQL>
SQL> startup mount;
ORACLE 例程已經啟動。
Total System Global Area 293601280 bytes
Fixed Size 1248600 bytes
Variable Size 96469672 bytes
Database Buffers 188743680 bytes
Redo Buffers 7139328 bytes
資料庫裝載完畢。
SQL> FLASHBACK DATABASE TO timestamp(to_date('2009-04-02 16:59:29','yyyy-mm-dd
hh24:mi:ss'));
閃回完成。
已用時間: 00: 00: 11.10
SQL> alter database open resetlogs;
資料庫已更改。
已用時間: 00: 00: 37.63
SQL>