对表15天前的数据刚刚进行归档,剩余数据不到原来的7%,需要在线重定义一下以降低其高水位线,执行前先检查一下
SQL> select blocks,bytes from user_segments where segment_name ='justin';
BLOCKS BYTES
---------- ----------
190592 1561329664
SQL> select num_rows,blocks from user_tables where table_name = 'justin';
NUM_ROWS BLOCKS
---------- ----------
117490 187535
对于这个表,我们知道归档后的数据分布情况,所以可以不用执行检查就使用在线重定义,但是在其余情况下,我们需要判断一下表的高水位线是否需要调整,rowid可以很好的帮助我们。
Rowid长度为18,其格式为000000.fff.bbbbbb.rrr,o代表object,f是相对文件号(对同一个表空间而言),b是block,r是row
查看目前表中实际占用的block块数目
SQL> select count(distinct(substr(rowid,1,15))) from justin;
COUNT(DISTINCT(SUBSTR(ROWID,1,
------------------------------
8595
表占用的block有将近20万,但是实际存放数据的只有8595
使用在线重定义进行重建,此步骤略去
SQL> select blocks,bytes from user_segments where segment_name ='justin';
BLOCKS BYTES
---------- ----------
9216 75497472
但user_tables里面统计信息为空,需要重新统计
SQL> select num_rows,blocks from user_tables where table_name = 'justin';
NUM_ROWS BLOCKS
---------- ----------
SQL> exec dbms_stats.gather_table_stats(ownname => user,tabname => 'justin',estimate_percent => 10);
PL/SQL procedure successfully completed
SQL> select num_rows,blocks from user_tables where table_name = 'justin';
NUM_ROWS BLOCKS
---------- ----------
117490 8474
此实验还证明 segment信息是及时的,而user_tables里的信息需要重新统计一下才能更新
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15480802/viewspace-689851/ ,如需转载,请注明出处,否则将追究法律责任。