CREATE OR REPLACE PROCEDURE HOLLEYWMS.clean_chip IS
/*********************************************************************
过程名: CLEAN_CHIP
功能点: 整理碎片,类似于电脑磁盘空间碎片整理功能
描述: 做成 作业计划(job)每周执行一遍;
提供参数:
返回参数:
开发: daizhicun
时间: 2006-02-06 17:27
*********************************************************************/
tmp_val VARCHAR2(500);
BEGIN
--1.整理高水位线(HWM);
FOR rec IN (SELECT table_name FROM user_tables)
LOOP
tmp_val := 'ALTER TABLE ' || rec.table_name || ' MOVE';
BEGIN
EXECUTE IMMEDIATE tmp_val;
dbms_output.put_line(tmp_val);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error: ' || tmp_val || '!');
END;
--2.释放空间,具体什么作用我也不清楚
tmp_val := 'ALTER TABLE ' || rec.table_name || ' deallocate unused';
BEGIN
EXECUTE IMMEDIATE tmp_val;
dbms_output.put_line(tmp_val);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error: ' || tmp_val || '!');
END;
END LOOP;
--3.把索引重建(碎片整理后,很多索引会变成UNUSABLE状态,必须重建后,让它变成valid状态)
FOR rec IN (SELECT index_name FROM user_indexes) --WHERE STATUS='UNUSABLE'
LOOP
tmp_val := 'ALTER INDEX ' || rec.index_name || ' REBUILD';
BEGIN
EXECUTE IMMEDIATE tmp_val;
dbms_output.put_line(tmp_val);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error: ' || tmp_val || '!');
END;
END LOOP;
--4.联合当前空间碎片,好像作用不大
tmp_val := 'ALTER TABLESPACE HOLLEYWMS COALESCE';
BEGIN
EXECUTE IMMEDIATE tmp_val;
dbms_output.put_line(tmp_val);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error: ' || tmp_val || '!');
END;
END;
问题探讨:
http://www.itpub.net/showthread.php?s=&threadid=872135;
http://daizhicun.blog.sohu.com/67293045.html;