程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> DB2數據庫 >> DB2教程 >> RecycleBin

RecycleBin

編輯:DB2教程

RecycleBin


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_Z喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc6O6PGJyPgoKU1FMJmd0OyBjcmVhdGUgdGFibGUgZGl5X29zKGlkIGludCk7PGJyPgqx7dLRtLS9qKGjPGJyPgpTUUwmZ3Q7IHNob3cgdXNlcjs8YnI+ClVTRVIgzqogJnF1b3Q7SFImcXVvdDs8YnI+ClNRTCZndDsgZHJvcCB0YWJsZSBkaXlfb3M7PGJyPgqx7dLRyb6z/aGjPGJyPgqy6b+00tG+rcm+s/21xLHtZGl5X29zOjxicj4KU1FMJmd0OyBzZWxlY3QgKiBmcm9tIHRhYiB3aGVyZSByb3dudW09MTs8YnI+Cjxicj4KPGJyPgpUTkFNRSAgICAgICAgICAgICAgICAgICAgICAgICAgVEFCVFlQRSAgQ0xVU1RFUklEPGJyPgotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gLS0tLS0tLSAtLS0tLS0tLS0tPGJyPgpCSU4kR0N2U0x4RkQ1bG5nVUFCL0FRQTV2Zz09JDAgVEFCTEU8YnI+Cjxicj4KU1FMJmd0OyBzaG93IHJlY3ljbGViaW48YnI+Ck9SSUdJTkFMIE5BTUUgICAgUkVDWUNMRUJJTiBOQU1FICAgICAgICAgICAgICAgIE9CSkVDVCBUWVBFICBEUk9QIFRJTUU8YnI+Ci0tLS0tLS0tLS0tLS0tLS0gLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tLSAtLS0tLS0tLS0tLS0tLS0tLS0tPGJyPgpESVlfT1MgICAgICAgICAgIEJJTiRHQ3ZTTHhGRDVsbmdVQUIvQVFBNXZnPT0kMCBUQUJMRSAgICAgICAgMjAxNS0wNi0xMDoyMzo0OTozMjxicj4KPGJyPgoKPGJyPgpTUUwmZ3Q7ICBzZWxlY3QgKiBmcm9tIGRiYV9yZWN5Y2xlYmluIHdoZXJlIG9yaWdpbmFsX25hbWU9"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$的創建和注釋,不斷的深入,會更加清楚的認知。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved