问题:

假如30g的数据文件,先建一个表A,20g,在建一个表B,1g,此时drop表A,水位线应该在21g的位置,然后move表B,水位线是否会回归1g ?

 

测试:

创建测试表空间 和 测试表A:

SYS @testdb> create tablespace TEST_HWM datafile '/oracle/db_file/testdb/test_hwm01.dbf' size 10m autoextend off;

Tablespace created.

SYS @testdb> create table A tablespace TEST_HWM as select * from dba_objects;

Table created.

SYS @testdb> insert into A select * from dba_objects;

14460 rows created.

SYS @testdb> /

14460 rows created.

SYS @testdb> /

14460 rows created.

SYS @testdb> /

14460 rows created.

SYS @testdb> commit;

Commit complete.

 

查看数据文件大小:

select file_id,file_name,bytes/1024 KB from dba_data_files where file_id = 8;
SYS @testdb> select file_id,file_name,bytes/1024 KB from dba_data_files where file_id = 8;

FILE_ID     FILE_NAME           KB
----------     ---------------------------------------- -  ---------
8     /oracle/db_file/testdb/test_hwm01.dbf    10240

 

查看高水位线

select file_id,max(block_id)*8 HWM_KB from dba_extents where file_id=8 group by file_id;
SYS @testdb> select file_id,max(block_id)*8 HWM_KB from dba_extents where file_id=8 group by file_id;

FILE_ID HWM_KB
----------   ----------
8          7168

 

回收站开启:

SYS @testdb> show parameter recyclebin

NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
recyclebin                             string             ON

 

创建B表:

create table B as select * from dba_objects where rownum<5;

 

查看高水位:

SYS @testdb> select file_id,max(block_id)*8 HWM_KB from dba_extents where file_id=8 group by file_id;

FILE_ID HWM_KB
---------- ----------
8      8192

 

drop 表A:

drop table A;

 

查看回收站:

SYS @testdb> col owner for a10
SYS @testdb> col original_name for a20
SYS @testdb> col object_name for a50
SYS @testdb> col operation for a10
SYS @testdb> col type for a10
SYS @testdb> col ts_name for a15
SYS @testdb> select owner,object_name,ORIGINAL_NAME,OPERATION,TYPE,TS_NAME,SPACE*8 SPACE_KB from dba_recyclebin;

OWNER   OBJECT_NAME          ORIGINAL_NAME    OPERATION     TYPE      TS_NAME             SPACE_KB
----------     -------------------------------------------------- --------------------    ----------          ----------         ---------------          ----------
SYS      BIN$rEWz58V+e2rgU24BAQEgDQ==$0    A           DROP       TABLE   TEST_HWM    7168

 

看看高水位:

SYS @testdb> select file_id,max(block_id)*8 HWM_KB from dba_extents where file_id=8 group by file_id;

FILE_ID HWM_KB
---------- ----------
8   8192

 

move表B:

alter table b move;

 

发现高水位反而涨了:

SYS @testdb> select file_id,max(block_id)*8 HWM_KB from dba_extents where file_id=8 group by file_id;

FILE_ID HWM_KB
---------- ----------
8    8256

 

purge回收占后move表B,水位线还是不会下降:

SYS @testdb> purge recyclebin;

Recyclebin purged.


SYS @testdb> select file_id,max(block_id)*8 HWM_KB from dba_extents where file_id=8 group by file_id;

FILE_ID HWM_KB
---------- ----------
8    8256

SYS @testdb> alter table b move;

Table altered.

SYS @testdb> select file_id,max(block_id)*8 HWM_KB from dba_extents where file_id=8 group by file_id;

FILE_ID HWM_KB
---------- ----------
8   8192

 

将表Bmove到别的表空间,水位线才会释放:

alter table b move tablespace users;

SYS @testdb> alter table b move tablespace users;

Table altered.

SYS @testdb> select file_id,max(block_id)*8 HWM_KB from dba_extents where file_id=8 group by file_id;

no rows selected

SYS @testdb> alter database datafile 8 resize 2m;

Database altered.

 

结论:

1、move表并不能降低表空间的高水位线。

2、purge回收站是没有用的。