表的年限比较久,水位线特别高,通过shrink 方式在线回收(生产要在空闲时操作)
–统计需要收缩表的信息(手工统计是为了下面查询水位线更准确)
SQL> exec dbms_stats.gather_table_stats(ownname=>‘USERNAME’,tabname=>‘TABLENAME’,estimate_percent=>10,method_opt=>‘for all indexed columns’,cascade=>TRUE);
–查询表得水位线 blocks是表的水位线
SQL> select num_rows,blocks from user_tables where table_name=‘TABLENAME’;
–开启表的行移动
SQL> alter table TABLENAME enable row movement;
–开始收缩表(如果数据量非常大需要执行很长时间)
SQL> alter table tablename shrink space;
–重新收集收缩表的信息
SQL> exec dbms_stats.gather_table_stats(ownname=>‘USERNAME’,tabname=>‘TABLENAME’,estimate_percent=>10,method_opt=>‘for all indexed columns’,cascade=>TRUE);
–查询收缩过表的水位线
SQL> select num_rows,blocks from user_tables where table_name=‘TABLENAME’;