在 Oracle10g 中,使用 shrink 可以手工回收表、索引组织表(IOT)、索引、分区、子分区、物化视图,或者物化视图日志的存储空间。当然,段所在的表空间必须是自动段空间管理的。默认情况下,Oracle 会将段中的数据移动到前端,调整高水位,然后释放空间。移动段中数据是需要 row movement 权限的,所以应提前设置你要 shrink 的对象 enable row movement。如果你的系统使用了基于 rowid 的触发器,也应该提前设置它为 disable 状态。shrink 有两个参数:COMPACT 和 CASCADE。COMPACT如果你指定 COMPACT 参数,那么 Oracle 只会整理段中的数据,将数据移动到段的前端,而不会调整高水位线,所以也不会释放空间。等数据整理完毕后,你得再次使用 alter table ... shrink space 语句来释放空间。如果你想使用两个占用时间短的步骤,而不是一个长时间的步骤,可以考虑分成两步完成 shrink。
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 wish to release the unused space, then you can use the appropriate COALESCE clause.
his clause for a cluster, a clustered table, or any object with a LONG column.
Segment shrink is not supported for LOB segments even if CASCADE is specified.
Segment shrink is not supported for tables with function-based indexes.
This clause does not shrink mapping tables or overflow segments of index-organized tables, even if you specify CASCADE.
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.
SQL> alter table test_yct enable row movement;表已更改。-- 将数据挪动到表的前端,但不回收高水位.
SQL> alter table test_yct shrink space compact;表已更改。-- 收缩表,回收高水位
SQL> alter table test_yct shrink space;表已更改。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/20542911/viewspace-621865/ ,如需转载,请注明出处,否则将追究法律责任。