|
在日常的工作和学习中,很多人在对数据库中的数据做了archive后,数据量会出现减少的情况,在这种前提下,原来定义的数据文件假如不进行收缩就会浪费很多的空间。在下文中,我们将详细介绍一种解决此问题的方法:
首先:停止listener,避免在rebuild时有dml操作。
◆1.利用toad的tools-->rebuild multiple objects对欲收缩的表空间所涉及的表及索引进行rebuild。(就是alter table table_name move tablespace 命令)。
例子:
alter table sics_history.cod_amount move
tablespace tbsp03
parallel (degree 4) ;
alter table sics_history.cod_amount noparallel;
alter index sics_history.ix0_cod_amount rebuild
tablespace tbsp03
parallel (degree 4) nologging
online;
alter index sics_history.ix0_cod_amount noparallel;
|
选择项中,我们可以选择rebuild associated indexes with tables.这样,在产生脚本时可以同时对index做rebuild。(注意:table如果move了表空间必须对index做rebuild)。
◆2.rebuild结束后,对数据文件的实际大小做评估:
(1)找出表空间所涉及的所有数据文件:
sql>select * from dba_data_files; --》可以获得file_id
|
(2)找到最大的block_id
sql>select max(block_id)*db_block_size/1024/1024 from dba_extents where file_id=..;
|
◆3.收缩数据文件的空间:
sql> alter database datafile 'path/data_file' resize xxxm; --此值来自于(2)
|
|