我们有同样的问题,使用同样的策略。
如果情况变得非常糟糕(索引、表的分配非常零碎,…),我们将尝试应用空间回收操作。
表必须允许行移动(类似于闪回):
alter table ttt启用行移动;
改变表ttt缩小空间;
然后重建所有索引。
我不知道你对维护窗口是怎么看的,如果应用程序必须一直可用,那就更难了,如果不是,你可以在离线时做一些“重新打包”。alter table ttt move tablespace sss“在重写表时,会做很多工作来清理混乱。您还可以指定新的存储参数,如数据块管理、大小…看一下文件。
我使用这样的脚本为整个数据库创建脚本:
SET SQLPROMPT "-- "
SET ECHO OFF
SET NEWPAGE 0
SET SPACE 0
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SET TRIMSPOOL ON
SET TERMOUT OFF
SET VERIFY OFF
SET TAB OFF
spool doit.sql
select 'prompt Enabling row movement in '||table_name||'...'||CHR (10)||'alter table '||table_name||' enable row movement;' from user_tables where table_name not like '%$%' and table_name not like '%QTAB' and table_name not like 'SYS_%';
select 'prompt Setting initial ext for '||table_name||'...'||CHR (10)||'alter table '||table_name||' move storage (initial 1m);' from user_tables where table_name not like '%$%' and table_name not like '%QTAB' and table_name not like 'SYS_%';
select 'prompt Shrinking space for '||table_name||'...'||CHR (10)||'alter table '||table_name||' shrink space;' from user_tables where table_name not like '%$%' and table_name not like '%QTAB' and table_name not like 'SYS_%';
select 'prompt Rebuilding index '||index_name||'...'||CHR (10)||'alter index '||index_name||' rebuild;' from user_indexes where status = 'UNUSABLE';
spool off
prompt now check and then run @doit.sql
exit