因為在12.2中,引入了新的特性:optimizer statistics advisor。
優化器統計信息顧問每天都會在維護窗口運行,auto_stats_advisor_task多次運行,
會消耗大量sysaux表空間,要是你有大量 partition table 這個會更消耗空間。
WRI$_ADV_OBJECTS為 AUTO_STATS_ADVISOR_TASK 或INDIVIDUAL_STATS_ADVISOR_TASK 保留的大量舊記錄會導致佔據大量 SYSAUX 空間。
AUTO_STATS_ADVISOR_TASK 用於自動統計顧問任務
INDIVIDUAL_STATS_ADVISOR_TASK 用於手動統計顧問任務
可以透過 oracle 自動排成去清掉舊資料,這邊可以看到預設的舊資料天數是多少
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';
把舊資料修改為10天
EXEC DBMS_ADVISOR.SET_TASK_PARAMETER(task_name=> 'AUTO_STATS_ADVISOR_TASK', parameter=> 'EXECUTION_DAYS_TO_EXPIRE', value => 10);
自動刪除: 正常情況下AUTO_STATS_ADVISOR_TASK 的 EXECUTION_DAYS_TO_EXPIRE 參數設置為 30(預設情況下)。因此,超過 30 天的舊記錄被標記為過期。
手動刪除: 可以使用以下命令手動清除過期的記錄,而不是依賴自動。這將清除超過 30 天保留期的舊記錄。
手動刪除指令:
exec prvt_advisor.delete_expired_tasks;
要是筆數已經太多會產生過多的undo , 可以直接truncate
*參考SYSAUX Tablespace Grows Rapidly After Upgrading Database to 12.2.0.1 or Above Due To Statistics Advisor (Doc ID 2305512.1)
看一下 等等要刪除的筆數
SELECT TASK_NAME, COUNT(*) CNT FROM DBA_ADVISOR_OBJECTS GROUP BY TASK_NAME ORDER BY CNT DESC;
把要保留的資料先備分
CREATE TABLE WRI$_ADV_OBJECTS_NEW AS SELECT * FROM WRI$_ADV_OBJECTS WHERE TASK_ID !=(SELECT DISTINCT ID FROM WRI$_ADV_TASKS WHERE NAME='AUTO_STATS_ADVISOR_TASK'); SQL> SELECT COUNT(*) FROM WRI$_ADV_OBJECTS_NEW;
刪除
TRUNCATE TABLE WRI$_ADV_OBJECTS;
還原
INSERT INTO WRI$_ADV_OBJECTS (ID,
TYPE,
TASK_ID,
EXEC_NAME,
ATTR1,
ATTR2,
ATTR3,
ATTR4,
ATTR5,
ATTR6,
ATTR7,
ATTR8,
ATTR9,
ATTR10,
ATTR11,
ATTR12,
ATTR13,
ATTR14,
ATTR15,
ATTR16,
ATTR17,
ATTR18,
ATTR19,
ATTR20,
OTHER,
SPARE_N1,
SPARE_N2,
SPARE_N3,
SPARE_N4,
SPARE_C1,
SPARE_C2,
SPARE_C3,
SPARE_C4)
SELECT ID,
TYPE,
TASK_ID,
EXEC_NAME,
ATTR1,
ATTR2,
ATTR3,
ATTR4,
ATTR5,
ATTR6,
ATTR7,
ATTR8,
ATTR9,
ATTR10,
ATTR11,
ATTR12,
ATTR13,
ATTR14,
ATTR15,
ATTR16,
ATTR17,
ATTR18,
ATTR19,
ATTR20,
OTHER,
SPARE_N1,
SPARE_N2,
SPARE_N3,
SPARE_N4,
SPARE_C1,
SPARE_C2,
SPARE_C3,
SPARE_C4
FROM WRI$_ADV_OBJECTS_NEW;
commit;
index rebuild
ALTER INDEX WRI$_ADV_OBJECTS_IDX_01 REBUILD online ;
ALTER INDEX WRI$_ADV_OBJECTS_PK REBUILD online ;