RecycleBin,oraclerecyclebin
SQL> select * from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
SQL> !cat /etc/issue
Enterprise Linux Enterprise Linux Server release 5.5 (Carthage)
Kernel \r on an \m
資源回收筒就是一個虛擬容器,用於儲存刪除的對象。在資源回收筒中,被刪除的對象將佔有建立時同樣的空間
我們可以通過參數 recyclebin來關閉開啟資源回收筒功能:
http://docs.oracle.com/cd/E11882_01/server.112/e40402/statviews_5160.htm#REFRN29036
下面不重點介紹Flashback。
SQL> show parameter recyclebin
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
recyclebin string on
SQL> alter system set recyclebin=off scope=spfile;
系統已更改。
SQL> show parameter recyclebin
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
recyclebin string OFF
建立表diy_os:
SQL> create table diy_os(id int);
表已建立。
SQL> show user;
USER 為 "HR"
SQL> drop table diy_os;
表已刪除。
查看已經刪除的表diy_os:
SQL> select * from tab where rownum=1;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BIN$GCvSLxFD5lngUAB/AQA5vg==$0 TABLE
SQL> show recyclebin
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
DIY_OS BIN$GCvSLxFD5lngUAB/AQA5vg==$0 TABLE 2015-06-10:23:49:32
SQL> select * from dba_recyclebin where original_name='DIY_OS';
OWNER OBJECT_NAME ORIGINAL_NAME OPERATION TYPE TS_NAME CREATETIME DROPTIME DROPSCN PARTITION_NAME CAN CAN RELATED BASE_OBJECT PURGE_OBJECT SPACE
------------------------------ ------------------------------ -------------------------------- --------- ------------------------- ------------------------------ ------------------- ------------------- ---------- -------------------------------- --- --- ---------- ----------- ------------ ----------
HR BIN$GCvSLxFD5lngUAB/AQA5vg==$0 DIY_OS DROP TABLE USERS 2015-06-10:23:49:16 2015-06-10:23:49:32 9610985 YES YES 78194 78194 78194 0
注意,如果刪除的是sys使用者的對象,則資源回收筒裡無記錄,oracle不建議在sys使用者裡建立對象:
SQL> show user;
USER 為 "SYS"
SQL> create table kernel(id int);
表已建立。
SQL> drop table kernel;表已刪除。
SQL> select * from dba_recyclebin where original_name='KERNEL';
未選定行
使用purge recyclebin可以清除資源回收筒裡的所有對象,可以purge user_recyclebin或者purge dba_recyclebin,通過purge tablespace tablespace_name,purge table user.table_name來選擇刪除
資源回收筒裡的對象
還需注意的是,當我們使用drop tablespace.....including contents命令來刪除資料表空間,資料表空間中的所有對象會被刪除,包括資源回收筒裡的內容。當使用drop user .....cascade命令來刪除使用者時,該使用者
下的所有對象會被刪除,包括資源回收筒裡的內容
SQL> purge table hr.diy_os;
表已清除。
SQL> select * from dba_recyclebin where original_name='DIY_OS';
未選定行
下面看下執行計畫:
SQL> select * from dba_recyclebin;
執行計畫
----------------------------------------------------------
Plan hash value: 1935272164
--------------------------------------------------------------------------------
--------------
| Id | Operation | Name | Rows | Bytes | Cost (%CP
U)| Time |
--------------------------------------------------------------------------------
--------------
| 0 | SELECT STATEMENT | | 2 | 336 | 12 (
9)| 00:00:01 |
|* 1 | FILTER | | | |
| |
|* 2 | HASH JOIN | | 2 | 336 | 12 (
9)| 00:00:01 |
| 3 | NESTED LOOPS | | | |
| |
| 4 | NESTED LOOPS | | 2 | 292 | 10 (
0)| 00:00:01 |
| 5 | NESTED LOOPS | | 2 | 202 | 6 (
0)| 00:00:01 |
| 6 | NESTED LOOPS OUTER | | 2 | 168 | 4 (
0)| 00:00:01 |
| 7 | TABLE ACCESS FULL | RECYCLEBIN$ | 2 | 146 | 2 (
0)| 00:00:01 |
| 8 | TABLE ACCESS CLUSTER | TS$ | 1 | 11 | 1 (
0)| 00:00:01 |
|* 9 | INDEX UNIQUE SCAN | I_TS# | 1 | | 0 (
0)| 00:00:01 |
| 10 | TABLE ACCESS CLUSTER | USER$ | 1 | 17 | 1 (
0)| 00:00:01 |
|* 11 | INDEX UNIQUE SCAN | I_USER# | 1 | | 0 (
0)| 00:00:01 |
|* 12 | INDEX RANGE SCAN | I_OBJ1 | 1 | | 1 (
0)| 00:00:01 |
| 13 | TABLE ACCESS BY INDEX ROWID| OBJ$ | 1 | 45 | 2 (
0)| 00:00:01 |
| 14 | INDEX FULL SCAN | I_USER2 | 97 | 2134 | 1 (
0)| 00:00:01 |
| 15 | NESTED LOOPS | | 1 | 29 | 2 (
0)| 00:00:01 |
|* 16 | INDEX FULL SCAN | I_USER2 | 1 | 20 | 1 (
0)| 00:00:01 |
|* 17 | INDEX RANGE SCAN | I_OBJ4 | 1 | 9 | 1 (
0)| 00:00:01 |
--------------------------------------------------------------------------------
--------------
下面摘自?/rdbms/admin/dsqlddl.bsq
create table recyclebin$
(
obj# number not null, /* original object number */
owner# number not null, /* owner user number */
original_name varchar2(32), /* Original Object Name */
operation number not null, /* Operation carried out */
/* 0 -> DROP */
/* 1 -> TRUNCATE (not supported) */
type# number not null, /* object type (see KQD.H) */
ts# number, /* tablespace number */
file# number, /* segment header file number */
block# number, /* segment header block number */
droptime date, /* time when object was dropped */
dropscn number, /* SCN of Tx which caused the drop */
partition_name varchar2(32), /* Name of the partition dropped */
/* NULL otherwise */
flags number, /* flags for undrop processing */
related number not null, /* obj one level up in heirarchy */
bo number not null, /* base object */
purgeobj number not null, /* obj to purge when purging this */
base_ts# number, /* Base objects Tablespace number */
base_owner# number, /* Base objects owner number */
space number, /* number of blocks used by the object */
con# number, /* con#, if index is due to constraint */
spare1 number,
spare2 number,
spare3 number
)
/
create index recyclebin$_obj on recyclebin$(obj#)
/
create index recyclebin$_ts on recyclebin$(ts#)
/
create index recyclebin$_owner on recyclebin$(owner#)
/
上面是資料字典recyclebin$的建立和注釋,不斷的深入,會更加清楚的認知。