bitscn.com
flashback table闪回drop的表(回收站闪回)
oracle的回收站功能由参数recyclebin参数决定,默认为on;
alter session set recyclebin=on;alter system set recyclebin=on scope=both;alter session set recyclebin=off;alter system set recyclebin=off scope=both;从回收站中还原删除的表查看删除表信息sql> select owner,object_name,original_name,type,ts_name,droptime,can_undrop from dba_recyclebin where owner='scott';--删除对象系统统一以bin$unique_id$version的形式命名 --can_undrop选项为no的选项为暂时不能恢复,比如索引依赖对应的表要先恢复 --删除的表已从回收站清除,则不能闪回。
查看回收站中的对象show recyclebin;select * from user_recyclebin/dba_recyclebin;手动清除回收站中的表purge table bin$6ah1cquityrgqab/aqbjbq==$0;清除回收站中特定表空间的所有对象purge tablespace 表空间名;清除回收站中特定表空间上特定用户的所有对象purge tablespace tablespace_name user scott;清除数据库中所有回收站中的对象purge dba_recyclebin;--管理员清空所有模式下的回收站purge recyclebin;--普通用户清除自己的回收站
使用回收站还原表
1.
sql> flashback table bin$5jxwcqj0ad/gqab/aqa2zq==$0 to before drop;sql> flashback table test01 to before drop;sql> flashback table test01 to before drop rename to test02;
2.
查询索引名,更改为原来的名称,如果是约束还要更改约束名称:
sql> select index_name, table_owner,table_name from user_indexes;sql> select table_name,constraint_name from user_constraints;sql> alter table test01 rename constraint bin$5jyrrned9gfgqab/aqa3rg==$0 to test01_pk;sql> alter index bin$5jyrrneb9gfgqab/aqa3rg==$0 rename to test01_pk;
--如果一个表删除多次,要还原较早版本的表,就必须指定在回收站中的表名
--如果在命令中指定原表名,将还原最近删除的版本
--如果删除后,表名已经重建,那需要用rename to选项重新指定其他表名。
删除的表也能查询
sql> select owner,object_name,original_name,type,can_purge,droptime from dba_recyclebin where owner='scott';owner object_name original_name type can droptime------------------------------ ------------------------------ -------------------------------- ------------------------- --- -------------------scott bin$5jyrrneg9gfgqab/aqa3rg==$0 test01 table yes 2013-09-13:04:59:31sql> desc bin$5jyrrneg9gfgqab/aqa3rg==$0;sql> select * from bin$5jyrrneg9gfgqab/aqa3rg==$0; id name---------- -------------------------------- 1 xycxyc
bitscn.com