閃回之 回收站、Flashback Drop (table、index、trigger等)

張衝andy發表於2017-01-12

一: Flashback Drop 操作流程


模式一:drop table 後未新建同名表

SQL> create table flashdrop as select * from user_objects;
Table created.

SQL> create bitmap index ind_flashdrop on flashdrop(object_type);
Index created.

SQL> drop table flashdrop;
Table dropped.
--檢視 recyclebin 內的物件
SQL> select original_name,object_name,type,droptime from recyclebin;
ORIGINAL_NAME OBJECT_NAME TYPE DROPTIME
-------------------------------- ------------------------------ ------------------------- -------------------
IND_FLASHDROP BIN$ESs42vP2YC3gUw0ZZAqeww==$0 INDEX 2015-03-13:08:08:19
FLASHDROP BIN$ESs42vP3YC3gUw0ZZAqeww==$0 TABLE 2015-03-13:08:08:19

SQL> flashback table flashdrop to before drop;
Flashback complete.

SQL> select original_name,object_name,type,droptime from recyclebin;
no rows selected
--檢視索引名字
SQL> col column_name for a40
SQL> SELECT index_name, column_name, descend FROM user_ind_columns WHERE table_name = 'FLASHDROP';
INDEX_NAME COLUMN_NAME DESC
------------------------------ ---------------------------------------- ----
BIN$ESs42vP2YC3gUw0ZZAqeww==$0 OBJECT_TYPE ASC
--索引改為原來的名字 (說明 閃回表 後,即使未給索引重新命名,執行計劃依然可以走索引)
SQL> alter index "BIN$ESs42vP2YC3gUw0ZZAqeww==$0" rename to IND_FLASHDROP;
Index altered.
--檢視是否成功改名
SQL> SELECT index_name, column_name, descend FROM user_ind_columns WHERE table_name = 'FLASHDROP';
INDEX_NAME COLUMN_NAME DESC
------------------------------ ---------------------------------------- ----
IND_FLASHDROP OBJECT_TYPE ASC

SQL> select count(*) from flashdrop;
COUNT(*)
----------
11
補充:
--檢視錶約束名
select CONSTRAINT_NAME,TABLE_NAME, COLUMN_NAME from user_cons_columns where TABLE_NAME='FLASHDROP';

模式二:drop table 後新建同名表

SQL> drop table flashdrop;
Table dropped.

SQL> create table flashdrop as select * from user_objects;
Table created.

SQL> select original_name,object_name,type,droptime from recyclebin;
ORIGINAL_NAME OBJECT_NAME TYPE DROPTIME
-------------------------------- ------------------------------ ------------------------- -------------------
IND_FLASHDROP BIN$ESs42vP4YC3gUw0ZZAqeww==$0 INDEX 2015-03-13:08:25:37
FLASHDROP BIN$ESs42vP5YC3gUw0ZZAqeww==$0 TABLE 2015-03-13:08:25:37

SQL> flashback table flashdrop to before drop;
flashback table flashdrop to before drop
*
ERROR at line 1:
ORA-38312: original name is used by an existing object

SQL> flashback table flashdrop to before drop rename to flashtable;
Flashback complete.

SQL> select original_name,object_name,type,droptime from recyclebin;
no rows selected

SQL> select count(*) from flashtable;
COUNT(*)
----------
11

模式三:drop table 後新建同名表,再 drop 新同名表

SQL> select count(*) from flashdrop;
COUNT(*)
----------
13

SQL> drop table flashdrop;
Table dropped.

SQL> create table flashdrop as select * from user_objects;
Table created.

SQL> insert into flashdrop(object_name) values('andy');
1 row created.

SQL> select count(*) from flashdrop;
COUNT(*)
----------
14
SQL> drop table flashdrop;
Table dropped.

SQL> select original_name,object_name,type,droptime from recyclebin;
ORIGINAL_NAME OBJECT_NAME TYPE DROPTIME
-------------------------------- ------------------------------ ------------------------- -------------------
FLASHDROP BIN$ESs42vP9YC3gUw0ZZAqeww==$0 TABLE 2015-03-13:08:42:21
FLASHDROP BIN$ESs42vP+YC3gUw0ZZAqeww==$0 TABLE 2015-03-13:08:56:16

SQL> select count(*) from "BIN$ESs42vP9YC3gUw0ZZAqeww==$0";
COUNT(*)
----------
13

SQL> select count(*) from "BIN$ESs42vP+YC3gUw0ZZAqeww==$0";
COUNT(*)
----------
14

SQL> flashback table "BIN$ESs42vP+YC3gUw0ZZAqeww==$0" to before drop;
Flashback complete.

SQL> select count(*) from flashdrop;
COUNT(*)
----------
14


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31383567/viewspace-2132366/,如需轉載,請註明出處,否則將追究法律責任。

相關文章