首页 > Linux操作系统 > Linux操作系统 > oracle shrink

oracle shrink

原创 Linux操作系统 作者:keeptrying 时间:2012-05-28 23:24:05 0 删除 编辑

一、shrink segment两个好处


You use online segment shrink to reclaim fragmented free space below the high water mark in an Oracle Database segment. The benefits of segment shrink are these:

l  Compaction of data leads to better cache utilization, which in turn leads to better online transaction processing (OLTP) performance.

l  The compacted data requires fewer blocks to be scanned in full table scans, which in turns leads to better decision support system (DSS) performance.




segment shrink分为两个阶段

1、 数据重组(compact):通过一系列insertdelete操作,将数据尽量排列在段的前面。在这个过程中需要在表上加Row ExclusiveRX)锁,即只在需要移动的行上加锁。由于涉及到rowid的改变,需要enable row movement。同时要disable基于rowidtrigger。这一过程对业务影响较小。

2、 HWM调整:第二阶段是调整HWM位置,释放空闲数据块。此过程需要在表上加X锁,会造成表上的所有DML语句阻塞。在业务特别繁忙的系统可能造成比较大的影响。


shrink space语句两个阶段都执行;

shrink space compact只执行第一个阶段。

如果系统业务比较繁忙,可以先执行shrink space compact重组数据,然后在业务不忙得时候再执行shrink space降低HWM释放空闲数据块。




1Shrink operations can be performed only on segments in locally managed tablespaces with automatic segment space management (ASSM).


2、 shrink必须开启行迁移功能!

Segment shrink requires that rows be moved to new locations. Therefore, you must first enable row movement in the object you want to shrink and disable any rowid-based triggers defined on the object.

alter table table_name enable row movement;




alter table shrink space [|compact|cascade];


:收缩表,降低high water mark

compact:重组表,只执行第一阶段,相当于把块中数据打结实了,但会保持high water mark

cascade:收缩表,降低high water mark,并且相关索引也要收缩一下。



Within an ASSM tablespace, all segment types are eligible for online segment shrink except these:


l   IOT mapping tables

l   Tables with rowid based materialized views

l   Tables with function-based indexes


来自 “ ITPUB博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录


  • 博文量
  • 访问量