当前位置:软件学习 > Flash >>

Flashback Table闪回drop的表(回收站闪回)

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:31

SQL> desc "BIN$5jYrRNeG9gfgQAB/AQA3rg==$0";

SQL> select * from "BIN$5jYrRNeG9gfgQAB/AQA3rg==$0";
        ID NAME
---------- --------------------------------
         1 xycxyc

 


CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,