Oracle 10g的新特性flashback
例:
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 >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
-------------------- -------------------