When the database is running out of space and you may need to take action to free up some space as soon as possible. Which tables to shrink? However, which tables should be shrunk? In Oracle 10g, DBMS_ADVISOR do the job to help help you(DBA ;-) to identify which tables should be shrunk by comparing the actual used space with HWM.
--create a table to store the output of DBMS_ADVISOR
create table result ( owner varchar2(30), table_name varchar2(30) not null, checkdate date, task_id number not null, task_name varchar2(30), message varchar2(4000), more_info varchar2(4000) ); --loop through all the tables owned by user USER1 DECLARE Task_Name VARCHAR2(100); Task_descr VARCHAR2(100); Object_Id NUMBER; Task_Ida NUMBER; BEGIN Task_Name := ''; -- a unique task name genetered by create task FOR Cur IN (SELECT * FROM User_Tables WHERE TableSpace_Name IS NOT NULL ORDER BY Table_Name) LOOP Task_descr := 'Table usage in ' ||Cur.Table_Name; Task_Name := NULL; dbms_Advisor.Create_Task('Segment Advisor',Task_Ida,Task_Name,Task_descr, NULL); dbms_Advisor.Create_Object(Task_Name,'TABLE','USER1',Cur.Table_Name, NULL,NULL,Object_Id); dbms_Advisor.Set_Task_Parameter(Task_Name,'RECOMMEND_ALL','TRUE'); dbms_Advisor.Execute_Task(Task_Name); INSERT INTO Result SELECT Owner, Cur.Table_Name, SYSDATE, Task_Id, Task_Name, Message, More_Info FROM dba_Advisor_Findings WHERE Task_Id = Task_Ida; END LOOP; END;
References:
http://www.oracle.com/technology/oramag/oracle/05-may/o35tuning.html
Metalink Doc ID:242736.

Post a Comment