都知道alter table move 或shrink space可以收缩段,用来消除部分行迁移,消除空间碎片,使数据更紧密,但move 跟shrink space还是有区别的。 SQL> select * from v$version; BANNER Table created. SQL> analyze table test compute statistics; Table analyzed. SQL> col SEGMENT_NAME for a10 SEGMENT_NA EXTENTS BLOCKS INIT SQL> col TABLE_NAME for a10 TABLE_NAME BLOCKS EMPTY_BLOCKS SQL> begin PL/SQL procedure successfully completed. SQL> analyze table test compute statistics; Table analyzed. SQL> select SEGMENT_NAME,EXTENTS,BLOCKS from user_segments where SEGMENT_NAME='TEST'; SEGMENT_NA EXTENTS BLOCKS SQL> select TABLE_NAME,BLOCKS,EMPTY_BLOCKS from user_tables where table_name='TEST'; TABLE_NAME BLOCKS EMPTY_BLOCKS SQL> delete from test where rownum<=50000; 50000 rows deleted. SQL> analyze table test compute statistics; Table analyzed. SQL> select SEGMENT_NAME,EXTENTS,BLOCKS from user_segments where SEGMENT_NAME='TEST'; SEGMENT_NA EXTENTS BLOCKS SQL> select TABLE_NAME,BLOCKS,EMPTY_BLOCKS from user_tables where table_name='TEST'; TABLE_NAME BLOCKS EMPTY_BLOCKS SQL> select count(distinct dbms_rowid.rowid_block_number(rowid)) used_blocks from test; USED_BLOCKS SQL> alter table test move; Table altered. SQL> analyze table test compute statistics; Table analyzed. SQL> select TABLE_NAME,BLOCKS,EMPTY_BLOCKS from user_tables where table_name='TEST'; TABLE_NAME BLOCKS EMPTY_BLOCKS SQL> select SEGMENT_NAME,EXTENTS,BLOCKS from user_segments where SEGMENT_NAME='TEST'; SEGMENT_NA EXTENTS BLOCKS SQL> alter table test enable row movement; Table altered. SQL> alter table test shrink space; Table altered. SQL> analyze table test compute statistics; Table analyzed. SQL> select SEGMENT_NAME,EXTENTS,BLOCKS from user_segments where SEGMENT_NAME='TEST'; SEGMENT_NA EXTENTS BLOCKS SQL> select TABLE_NAME,BLOCKS,EMPTY_BLOCKS from user_tables where table_name='TEST'; TABLE_NAME BLOCKS EMPTY_BLOCKS
注意: SQL> drop table test; Table dropped. SQL> create table test (id number) storage (initial 10m next 1m) tablespace users; Table created. SQL> analyze table test compute statistics; Table analyzed. SQL> select SEGMENT_NAME,EXTENTS,BLOCKS,INITIAL_EXTENT/1024/1024 init from user_segments where SEGME SEGMENT_NA EXTENTS BLOCKS INIT SQL> select TABLE_NAME,BLOCKS,EMPTY_BLOCKS from user_tables where table_name='TEST'; TABLE_NAME BLOCKS EMPTY_BLOCKS SQL> alter table test move storage (initial 1m); Table altered. SQL> analyze table test compute statistics; Table analyzed. SQL> select SEGMENT_NAME,EXTENTS,BLOCKS,INITIAL_EXTENT/1024/1024 init from user_segments where SEGME SEGMENT_NA EXTENTS BLOCKS INIT SQL> select TABLE_NAME,BLOCKS,EMPTY_BLOCKS from user_tables where table_name='TEST'; TABLE_NAME BLOCKS EMPTY_BLOCKS 2.使用move时,会改变一些记录的ROWID,所以MOVE之后索引会变为无效,需要REBUILD。 |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/14844492/viewspace-1046764/ ,如需转载,请注明出处,否则将追究法律责任。