首先要收集表的统计信息,然后通过统计信息计算出实际空间于user_extents占用的空间相比,一般碎片超过25%就可以考虑shrink或者move整理表碎片。
查询SQL参考:select t.table_name,
avg_row_len * num_rows / (1 - pct_free / 100) / 8192 actual_block,
alloc_block,
1 - ((avg_row_len * num_rows / (1 - pct_free / 100) / 8192) / alloc_block) percen,
'alter table '||t.table_name||'enable row movement'||';' enable_row,
'alter table '||t.table_name||'shrink space'||';' ddl_shrink
from (select segment_name, sum(blocks) alloc_block
from user_extents
having sum(blocks) > 8
group by segment_name) a,
user_tables t
where a.segment_name = t.table_name
and t.table_name='XXXX'
order by 4 des