Oracle從回收站恢復刪除的表


Oracle從回收站恢復刪除的表

Oracle 10g以后的版本中引入了”回收站”(Recycle Bin)的概念,刪除的對象統一放入回收站,以BIN$最為前綴命名.用戶刪除某個表,可以很容易的從”回收站”中還原回來,但在9i以前是對於刪除表這樣的DDL操縱是不能直接還原回來的,通常需要做不完全恢復或是使用EXP/IMP來恢復.  
1.查看當前回收站功能是否開啟(默認情況下是開啟的) 
SQL> column value format a10; 
SQL> select value from V$parameter where name = ’recyclebin’;  
VALUE 
———-
 On 
可以使用如下命令開啟或關閉該功能. 
SQL> alter system set recyclebin = on scope=spfile; 
或    SQL> alter session set recyclebin = on scope=spfile;  
SQL> alter system set recyclebin = off scope=spfile; 或    SQL> alter session set recyclebin = off scope=spfile;  
2.查看回收站里的內容 
SQL> show recyclebin; 
或    SQL> select * from user_recyclebin; 下面將創建的表刪除后放入回收站 
SQL> show user; user is ”HXL” 
SQL> create table test_rbin(val number); 
Table created. 
SQL> insert into test_rbin(val) values(10); 
1 row created.
 SQL> commit; 
Commit complete. 
SQL> drop table test_rbin; Table dropped. 
SQL> show recyclebin; 
ORIGINAL NAME    RECYCLEBIN NAME    OBJECT TYPE  DROP TIME 
—————-  ———————————————–     ——–   ——– 
TEST_RBIN  BIN$S4u3UNw0QQ6t6LRxMMz7hQ==$0 TABLE  2012-06-22:15:01:30  
 
3.從回收站恢復刪除的表 
可以使用如下語句從回收站恢復刪除的表 
flashback table table_name to before drop;
例如恢復剛才刪的表
SQL> flashback table test_rbin to before drop;
 Flashback complete. 
SQL> select * from test_rbin;
 VALUE 
———- 
10 
在恢復的過程的同時我們可以將表另外命名,命令如下: 
flashback table << dropped table name >>  to before drop rename to <<new table name >>
 
SQL>flashback table test_rbin to before drop rename to test_rbin1;  
 
Oracle從回收站恢復是按照”降序”恢復的,比如連續3次刪除同樣一個表(刪除后再創建,再刪除),恢復的是先恢復最后一次刪除的表. 
SQL> show user; USER is ”HXL” 
SQL> drop table test_rbin;
 Table dropped. 
SQL> create table test_rbin (col1 number);
 Table created. 
SQL> insert into test_rbin values (1); 
1 row created.
 SQL> commit; 
Commit complete. 
SQL> drop table test_rbin; 
Table dropped. 
SQL> create table test_rbin (col1 number); 
Table created. 
SQL> insert into test_rbin values (2); 
1 row created. 
SQL> commit; 
Commit complete. 
SQL> drop table test_rbin; 
Table dropped. 
SQL> create table test_rbin (col1 number); 
Table created. 
SQL> insert into test_rbin values (3);
 1 row created. 
SQL> commit; 
Commit complete. 
SQL> drop table test_rbin;
 Table dropped. 
SQL> show recyclebin; 
ORIGINAL NAME    RECYCLEBIN NAME    OBJECT TYPE  DROP TIME 
—————-  ———————————————–       ——–  ——————- 
TEST_RBIN  BIN$gGHkV/xQSSaQ5bG0PikSAg==$0 TABLE  2012-06-22:15:31:21 
TEST_RBIN  BIN$xVKygKwJTJa+8zmu4BJzvQ==$0 TABLE  2012-06-22:15:30:53 
TEST_RBIN  BIN$R7As9PsYRva7CY6cnAjROw==$0 TABLE  2012-06-22:15:30:23 
TEST_RBIN  BIN$0R+cRKhDTFu+8ShBjLDpqg==$0 TABLE  2012-06-22:15:29:27   
SQL> select * from test_rbin1; COL1 
———-
 3 
SQL> select * from test_rbin2; COL1 
———-
 2 
SQL> select * from test_rbin3; COL1 
———-

4.清空回收站 
清空某個表,清空表的同時也將該表上的索引和約束都一起清空了的. 
SQL> purge table << table_name >> 清空索引,保留表數據 
SQL> purge  index <<index_name >>; 清空表空間 
SQL> purge tablespace <<table space name>>; 
清空某個用戶下的表空間 
SQL> purge tablespace <<table space name>> user <<user name>>; 清空整個回收站 
SQL> purge recyclebin; 
刪除表的同時從回收站中清除 
SQL> drop table << Table_Name >> purge; 
  說明: 
若表上建有索引,在恢復表后,索引也一起恢復了且不會失效,但索引名字不是之前的名字了,而是以BIN$前綴的名字,這個時候按需要可以命名該索引(alter index ”BIN$XXXXX” rename to original_name,注意回收站里的名稱需要雙引號); 
表以及表上的索引和約束,刪除會進入到回收站,其他對象如存儲過程,包,函數刪除后,在回收站是找不到的,可以說回收站只收集刪除后的表. 
一旦表從回收站清除后,就不能使用FLASHBACK恢復了;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM