高水位线

当表随着数据的增加,会使用越来越多的块,HWM会升高,当删除一些数据后,可能会产生很多空块(不包含数据的块),但它们仍在HWM之下。为了降低高水位线,有必要对表进行重组 (reorganization):
ALTER TABLE T ENABLE ROW MOVEMENT;
ALTER TABLE T SHRINK SPACE;


什么时候应该收缩表空间呢?

从统计信息表中dba_tables,可以计算出表共使用的空间(AVG_ROW_LEN * NUM_ROWS),和占用的块数(BLOCKS)(高水位之下的块),据此大概可知高水位之下空闲块的数量,以决定是否收缩表。


ALTER TABLE <table_name> SHRINK SPACE COMPCAT;的使用并查看使用效果:

BLOCKS变为1,也即降低了高水位。


shrink_clause

The shrink clause lets you manually shrink space in a table, index-organized table or its overflow segment, index, partition, subpartition, LOB segment, materialized view, or materialized view log. This clause is valid only for segments in tablespaces with automatic segment management. By default, Oracle Database compacts the segment, adjusts the high water mark, and releases the recuperated space immediately.

Compacting the segment requires row movement. Therefore, you must enable row movement for the object you want to shrink before specifying this clause. Further, if your application has any rowid-based triggers, you should disable them before issuing this clause.

COMPACT If you specify COMPACT, then Oracle Database only defragments the segment space and compacts the table rows for subsequent release. The database does not readjust the high water mark and does not release the space immediately. You must issue another ALTER TABLE ... SHRINK SPACE statement later to complete the operation. This clause is useful if you want to accomplish the shrink operation in two shorter steps rather than one longer step.

For an index or index-organized table, specifying ALTER [INDEX | TABLE] ... SHRINK SPACE COMPACT is equivalent to specifying ALTER [INDEX | TABLE ... COALESCE. The shrink_clause can be cascaded (please refer to the CASCADE clause, which follows) and compacts the segment more densely than does a coalesce operation, which can improve performance. However, if you do not want to release the unused space, then you can use the appropriate COALESCE clause.

CASCADE If you specify CASCADE, then Oracle Database performs the same operations on all dependent objects of table, including secondary indexes on index-organized tables.

Restrictions on the shrink_clause The shrink_clause is subject to the following restrictions:

You cannot specify this clause for a cluster, a clustered table, or any object with a LONG column.

Segment shrink is not supported for tables with function-based indexes or bitmap join indexes.

This clause does not shrink mapping tables of index-organized tables, even if you specify CASCADE.

You cannot specify this clause for a compressed table.

You cannot shrink a table that is the master table of an ON COMMIT materialized view. Rowid materialized views must be rebuilt after the shrink operation.


明白以下语句的作用:
ALTER TABLE <table_name> ENABLE ROW MOVEMENT -->前提条件

ALTER TABLE <table_name> SHRINK SPACE [ <NULL> | COMPACT | CASCADE ];

ALTER TABLE <table_name> SHRINK SPACE COMPCAT; -->缩小表和索引,不移动高水位线,不释放空间

ALTER TABLE <table_name> SHRINK SPACE; -->收缩表,降低高水位线;

ALTER TABLE <table_name> SHRINK SPACE CASCADE; -->收缩表,降低高水位线,并且相关索引也要收缩一下

ALTER TABLE <table_name> MODIFY LOB (lob_column) (SHRINK SPACE); -->收缩LOB段

ALTER INDEX IDXNAME SHRINK SPACE; -->索引段的收缩,同表段


使用 show_space (来自tom)区分段管理为manual,还是auto
DBMS_SPACE.UNUSED_SPACE Returns information about unused space in an object (table, index, or cluster).
DBMS_SPACE.FREE_BLOCKS Returns information about free data blocks in an object (table, index, or cluster) whose segment free space is managed by free lists (segment space management is MANUAL).
DBMS_SPACE.SPACE_USAGE Returns information about free data blocks in an object (table, index, or cluster) whose segment space management is AUTO.


Total Blocks --总块数
Full Blocks --填满的块数
FS4 Blocks
FS3 Blocks
FS2 Blocks
从以上几个输出也可以看出是否需要对表进行收缩。

http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/schema.htm#sthref2156

参考:
http://blog.csdn.net/robinson_0612/article/details/6630673


你可能感兴趣的:(高水位线)