天天看点

oracle recyclebin详解,Oracle recyclebin介绍

近日为某客户做数据库巡检,发现数据库recycle bin中有几千个被删除的对象,于是建议客户清理recycle bin中的对象,释放空间,客户问这些对象占用空间吗?存放在哪里的?

这些被删除的对象当然是存放在硬盘上的,官方方档介绍recycle bin 如下:

The recycle bin is actually a data dictionary table containing information about dropped objects. Dropped tables and any associated objects such as indexes,

constraints, nested tables, and the likes are not removed and still occupy space. They continue to count against user space quotas, until specifically purged

from the recycle bin or the unlikely situation where they must be purged by the database because of tablespace space constraints

recycle bin事实上是一个数据字典表,包含被删除对象的信息,例如:表、索引、约束等,recycle bin中被删除的对象不会被remove,仍然占用空间。

Each user can be thought of as having his own recycle bin, since unless a user has the SYSDBA privilege, the only objects that the user has access to in the

recycle bin are those that the user owns. A user can view his objects in the recycle bin using the following statement:SELECT * FROM RECYCLEBIN;

每个用户都有自己的recycle bin,对象的拥有者都可以访问自己的recycle bin,除非具有sysdba权限,可以通过select * from recyclebin查询,默认recycle bin是开启的。

1、禁用recycle bin:

ALTER SESSION SET recyclebin = OFF;

ALTER SYSTEM SET recyclebin = OFF;

2、开启recycle bin:

ALTER SESSION SET recyclebin = ON;

ALTER SYSTEM SET recyclebin = ON;

测试:

1、创建表空间

[email protected]>create tablespace recycle datafile '/u01/app/oracle/oradata/jzh/recycle' size 10M;

Tablespace created.

2、创建用与测试表

[email protected]>create user test identified by test default tablespace recycle;

User created.

[email protected]>grant dba to test;

Grant succeeded.

[email protected]>conn test/test

Connected.

[email protected]>create table test as select * from dba_objects;

Table created.

3、删除test表

[email protected]>select * from recyclebin;

no rows selected

[email protected]>drop table test;

Table dropped.

[email protected]>select OBJECT_NAME,ORIGINAL_NAME,OPERATION,TYPE,DROPTIME from recyclebin;

OBJECT_NAME                    ORIGINAL_NAME                    OPERATION TYPE                      DROPTIME

------------------------------ -------------------------------- --------- ------------------------- -------------------

BIN$GJ+BrKeuDfDgU28BqMAPIg==$0 TEST                             DROP      TABLE                     2015-06-16:16:39:03

4、查询test用户下对象

[email protected]>select * from tab;

TNAME                          TABTYPE  CLUSTERID

------------------------------ ------- ----------

BIN$GJ+BrKeuDfDgU28BqMAPIg==$0 TABLE

5、查询对象BIN$GJ+BrKeuDfDgU28BqMAPIg==$0所在表空间,大小等信息

[email protected]>select SEGMENT_NAME,SEGMENT_TYPE,TABLESPACE_NAME,BYTES,BLOCKS from user_segments where segment_name='BIN$GJ+BrKeuDfDgU28BqMAPIg==$0';

SEGMENT_NAME                                                                      SEGMENT_TYPE       TABLESPACE_NAME                     BYTES     BLOCKS

--------------------------------------------------------------------------------- ------------------ ------------------------------ ---------- ----------

BIN$GJ+BrKeuDfDgU28BqMAPIg==$0                                                    TABLE              RECYCLE                           8716288       1064

以上可以看出BIN$GJ+BrKeuDfDgU28BqMAPIg==$0对象依然存储在recycle表空间,大小为8716288字节,共1064个blocks

总结:1、被drop之后的表依然存储在原位置,大小无变化,占用空间;

2、在原位置被drop的对象被标记为可覆盖;

3、当原表空间无free的空间时,该位置就会被覆盖;