SQL> col TASK_NAME format a25
SQL> col parameter_name format a35
SQL> col parameter_value format a20
SQL> set lines 120
SQL> select TASK_NAME,parameter_name, parameter_value FROM DBA_ADVISOR_PARAMETERS WHERE task_name='AUTO_STATS_ADVISOR_TASK' and PARAMETER_NAME='EXECUTION_DAYS_TO_EXPIRE';
SQL> conn / as sysdba
SQL> exec prvt_advisor.delete_expired_tasks;
如果执行上述命令时,遇到了ORA-01555错误,请使用如下循环办法来每次清理50天数据:
set serveroutput on
DECLARE
v_oldest INTEGER := 730; -- Two years
v_increment INTEGER := 50;
v_cur_age INTEGER;
v_min_age INTEGER := 30; -- Retain one month.
BEGIN
v_cur_age := v_oldest;
WHILE v_cur_age >= v_min_age LOOP
dbms_sqltune.set_tuning_task_parameter(task_name => 'AUTO_STATS_ADVISOR_TASK', parameter => 'EXECUTION_DAYS_TO_EXPIRE', value => v_cur_age);
prvt_advisor.delete_expired_tasks;
v_cur_age := v_cur_age - v_increment;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Execution halted with error number ' || sqlerrm);
END;
/
完成数据清理后,请使用如下命令来释放空间并重建index。
SQL> alter table WRI$_ADV_OBJECTS move;
SQL> alter index WRI$_ADV_OBJECTS_PK rebuild;
SQL> alter index WRI$_ADV_OBJECTS_IDX_01 rebuild;
SQL> alter index WRI$_ADV_OBJECTS_IDX_02 rebuild;
样例:
再执行清理前:(查询历史记录情况)
SQL> col task_name format a25
SQL> col EXECUTION_NAME format a15
SQL> select TASK_ID,TASK_NAME,EXECUTION_NAME ,execution_start from dba_advisor_executions where TASK_NAME='AUTO_STATS_ADVISOR_TASK';
SQL> alter table WRI$_ADV_OBJECTS move;
alter table WRI$_ADV_OBJECTS move
*
ERROR at line 1:
ORA-65040: operation not allowed from within a pluggable database