flashback drop后表空间不足直接删除回收站中删除表所占空间的演示
DROP表后还可以从回收站中查到表,但是在DBA_FREESPACE中已经把DROP的表的空间回收为可用了。
要是此时在表空间建表并空间不断增长,回收站中DROP表 最终会被覆盖或者叫被删除来释放空间,此时闪回DROP的表会报错:ORA-38305: object not in RECYCLE BIN
如果创建的表空间是自动扩展的,则会首先先将回收站中表彻底删除,如表空间内的可用空间还不够,才会自动扩展。
实验如下:
1.建一个空间小点的表空间,表空间允许自动扩展。
SQL> create tablespace test1 datafile'/u01/app/oracle/oradata/bys001/test1.dbf' size 15m autoextend on;
Tablespace created
SQL> select file#,name,bytes/1024/1024 MB from v$datafile;
FILE# NAME MB
---------- -------------------------------------------------------------------------------- ----------
1 /u01/app/oracle/oradata/bys001/system01.dbf 700
2 /u01/app/oracle/oradata/bys001/sysaux01.dbf 570
3 /u01/app/oracle/oradata/bys001/undotbs01.dbf 85
4 /u01/app/oracle/oradata/bys001/users01.dbf 37.5
5 /u01/app/oracle/oradata/bys001/example01.dbf 100
6 /u01/app/oracle/oradata/bys001/catalog1.dbf 50
7 /u01/app/oracle/oradata/bys001/test1.dbf 15
8 /u01/app/oracle/oradata/bys001/bys_flashback.dbf 10
2.创建一个占空间大比较的表
SQL> create table test9 tablespace test1 as select * from dba_objects where 1=0;
Table created
SQL> select tablespace_name,bytes/1024/1024 mb from dba_free_space where tablespace_name='TEST1';
TABLESPACE_NAME MB
------------------------------ ----------
TEST1 14 --------test1表空间空闲大小是14M,
SQL> insert into test9 select * from dba_objects;
72751 rows inserted
SQL> select tablespace_name,bytes/1024/1024 mb from dba_free_space where tablespace_name='TEST1';
TABLESPACE_NAME MB
------------------------------ ----------
TEST1 5 ----在test9表空间插入数据后,test1表空间空闲大小是5M
SQL> commit;
Commit complete
SQL> col segment_name for a15
SQL> col tablespace_name for a15
SQL> select segment_name,segment_type,tablespace_name,extents,bytes/1024 KB from dba_segments where segment_name like 'TEST9%';
SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENTS KB
--------------- ------------------ --------------- ---------- ----------
TEST9 TABLE TEST1 24 9216 ---test9的大小是9M
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
TEST9 TABLE
3.删除表并查询回收站
SQL> drop table test9;
Table dropped
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BIN$4LABIoAgQQ7gQFXeqEBxZg==$0 TABLE
4.查询表空间的剩余空间,发现删除到回收站的表的空间在dba_free_space中已经被释放了。
SQL> select segment_name,segment_type,tablespace_name,extents,bytes/1024 KB from dba_segments where segment_name like 'TEST9%';
SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENTS KB
--------------- ------------------ --------------- ---------- ----------
SQL> select tablespace_name,sum(bytes/1024/1024) as freespace from dba_free_space where tablespace_name='TEST1' group by tablespace_name;
TABLESPACE_NAME FREESPACE
--------------- ----------
TEST1 14 ---表空间空闲空间14M,回到test9插入数据前的状态
SQL>show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST9 BIN$5hvFkoUf4jjgQKjA0wFMJg==$0 TABLE 2013-09-11:21:41:00
SQL> select count(*) from "BIN$4LABIoAgQQ7gQFXeqEBxZg==$0";
COUNT(*)
----------
72553
5.建一个占空间大的新表,发现回收站中删除表test9已经被彻底删除。
SQL> create table test3 tablespace test1 as select * from dba_objects;
Table created
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
TEST3