1. 程式人生 > 實用技巧 >資料庫自動收集統計資訊:auto optimizer stats collection 相關的操作和注意事項

資料庫自動收集統計資訊:auto optimizer stats collection 相關的操作和注意事項

1、檢視自動收集統計資訊的job是否開啟:

SQL> select client_name,status from DBA_AUTOTASK_TASK;
CLIENT_NAME STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection           ENABLED  <<=== 
auto space advisor                        ENABLED
sql tuning advisor                        ENABLED

SQL
> select client_name,status from Dba_Autotask_Client; CLIENT_NAME STATUS ---------------------------------------------------------------- -------- auto optimizer stats collection DISABLED <<=== auto space advisor ENABLED sql tuning advisor ENABLED

這是預期的行為。

這些檢視假設client和task之間存在一對一的關係。

task可以被不同/多個client使用。因此,即使我們禁用了client,DBA_AUTOTASK_TASK仍然可以顯示啟用狀態。在當前版本中,task只有一個client。但是在oracle的未來版本中,task可以有多個客戶機,因此DBA_AUTOTASK_TASK中的狀態將顯示為啟用。

所以檢查狀態的正確方法是通過DBA_AUTOTASK_CLIENT。

2、預設收集統計資訊的視窗的查詢:

ORACLE 11g/12c中預設有9個統計資訊自動收集視窗。其中WEEKNIGHT_WINDOW、WEEKEND_WINDOW是為了相容之前的版本所保留的視窗,預設不啟用。
其他7個啟用的統計資訊自動收集視窗分為
工作日模式(週一~週五)和週末模式(週六~週日)。
工作日模式的收集視窗為22:00-2:00(+1),持續時間為4小時;
週末模式的收集視窗為6:00-2:00(+1),持續時間為20小時。

當前收集視窗引數設定:
select window_name,repeat_interval,duration,enabled,active from dba_scheduler_windows;

3、檢視歷史autotask_client的執行情況:

col CLIENT_NAME for a32
col window_name for a15
col WINDOW_START_TIME for a40
col WINDOW_DURATION for a40
SELECT * FROM dba_autotask_client_history WHERE client_name LIKE '%stats%' order by WINDOW_START_TIME;

Bug 12629687 DBA_AUTOTASK_CLIENT_HISTORY.WINDOW_END_TIME continues being updated

4、檢視autotask_client中job的歷史執行情況:

col CLIENT_NAME for a20
col window_name for a15
col WINDOW_START_TIME for a40
col WINDOW_DURATION for a40
col job_name for a30
col JOB_START_TIME for a50
col JOB_DURATION for a40
SELECT CLIENT_NAME,WINDOW_NAME,WINDOW_START_TIME,WINDOW_DURATION,JOB_NAME,JOB_START_TIME,JOB_DURATION,JOB_STATUS 
FROM DBA_AUTOTASK_JOB_HISTORY WHERE client_name LIKE '%stats%' order by WINDOW_START_TIME;

5、檢視視窗當前的詳細情況(是否在執行中):

select * from DBA_AUTOTASK_WINDOW_CLIENTS

6、檢視ALL_SCHEDULER_WINDOW_LOG中視窗的關閉時間:

select LOG_ID,LOG_DATE,WINDOW_NAME,OPERATION from ALL_SCHEDULER_WINDOW_LOG where WINDOW_NAME='MONDAY_WINDOW' order by LOG_DATE;

Bug 12629687 DBA_AUTOTASK_CLIENT_HISTORY.WINDOW_END_TIME continues being updated

Description
After closing a scheduler window, the column WINDOW_END_TIME of the table
DBA_AUTOTASK_HISTORY continues being updated.

Rediscovery Notes
By querying the view DBA_AUTOTASK_WINDOW_HISTORY, if the close time of one of
the windows there that has already been closed is systimestamp instead of the
actual close time (which can be found in DBA_SCHEDULER_WINDOW_LOG) then that
would mean the bug persists.

Workaround

7、修改統計資訊視窗的步驟:

1)確認並備份當前收集視窗引數設定。
參考命令:
select window_name,repeat_interval,duration,enabled,active from dba_scheduler_windows;

2)對收集視窗引數進行調整
根據需要對收集視窗引數進行個性化調整。參考命令:
exec dbms_scheduler.set_attribute(name=>'SATURDAY_WINDOW',attribute=>'repeat_interval',value=>'freq=daily;byday=SAT;byhour=6;byminute=0;bysecond=0');
啟用調整後的收集視窗。參考命令: exec DBMS_SCHEDULER.ENABLE(
' SATURDAY_WINDOW ');
3)檢查確認 確認引數調整是否生效,參考1)中命令。 檢查視窗任務狀態是否正確。 參考命令: select window_group_name, enabled, number_of_windows, next_start_date from dba_scheduler_window_groups where window_group_name='MAINTENANCE_WINDOW_GROUP';
注:next_start_date為下次視窗啟動時間,正常應為工作日模式的22:00或者週末模式的6:00.
4)狀態異常情況處理 如果視窗的ENABLED狀態為FALSE,則利用如下命令啟用: exec DBMS_SCHEDULER.ENABLE(' XXX_WINDOW ');

8、想要殺掉視窗內收集統計資訊的job:

dba_scheduler_running_jobs

dba_jobs_running

有一定的區別,暫時還未測試。