对于表的恢复
db_flashback_retention_target参数决定删除表以及表中数据保留时间
sql>conn / as sysdba
Connected.
sql>alter system set db_flashback_retention_target=3600;
System altered.
sql>
确认处于归档模式
sql>select dbid,name,log_mode from v$database;
DBID NAME LOG_MODE
---------- --------- ------------
1573521836 FENGZIARCHIVELOG
sql>
sql>conn u2/u2
sql>select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BB2 TABLE
EMPTY TABLE
TEMP TABLE
sql>drop table bb2;
Table dropped.
查询回收站
sql>show recyclebin
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
BB2 BIN$98CBLGsSLR/gQKjACjgQQQ==$0 TABLE 2014-04-24:09:09:44
恢复表
sql>flashback table bb2 to before drop;
Flashback complete.
sql>select * from bb2;
ID
----------
1
12 rows selected.
sql>create table bb2 as select * from temp;
Table created.
BB2 BIN$98Cx0ajtOxDgQKjACjgQYg==$0 TABLE 2014-04-24:09:23:20
BB2 BIN$98Cx0ajuOxDgQKjACjgQYg==$0 TABLE 2014-04-24:09:24:59
sql>
如果还使用BB2名称恢复表的话,得到的表为最后一次删除的表内容。
想要恢复之前的表需要
BB2BIN$98Cx0ajtOxDgQKjACjgQYg==$0TABLE2014-04-24:09:23:20
sql> flashback table "BIN$98Cx0ajtOxDgQKjACjgQYg==$0" to before drop;
sql>
对于表中行的恢复
这种方法有点时候是不实用的
sql>select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YY
-------------------
2014-04-24 09:38:05
sql>update bb2 set id=id+1 where id=1;
12 rows updated.
sql>commit;
Commit complete.
sql>alter table bb2 enable row movement;
Table altered.
sql>flashback table bb2 to timestamp to_timestamp('2014-04-24 09:38:05','yyyy-mm-dd hh24:mi:ss');
sql>alter table bb2 disable row movement;
sql>
比较实用的方法 2
14 rows selected.
2014-04-24 09:55:07
sql>delete bb2 where id=2;
2 rows deleted.
sql>select * from bb2 as of timestamp to_timestamp('2014-04-24 09:55:07','yyyy-mm-dd hh24:mi:ss')where id=2;
sql>select * from bb2 where id=2;
no rows selected