參考文獻:
Oracle11g 統計資訊(一)-----統計資訊自動收集任務
背景:
在使用cacti監控oracle資料庫IO的時候發現每天晚上10點鐘的時候oracle資料庫讀寫明顯增加,如下圖所示:
對這個問題,後來查了一下是因為oracle在執行一個資訊自動收集任務。oracle 11g中統計資訊自動收集任務的名稱是auto optimizer stats collection。11g中自動任務預設的執行時間視窗(oracle時間視窗介紹)為:
- 週一到週五是晚上10點開始到2點結束
- 週末是早上六點,持續20個小時。
1、檢視自動收集任務及狀態
select client_name,status from Dba_Autotask_Client where client_name='auto optimizer stats collection';
2、停止自動收集任務
--關閉資訊自動收集任務 BEGIN DBMS_AUTO_TASK_ADMIN.DISABLE( client_name => 'auto optimizer stats collection', operation => NULL, window_name => NULL); END; / PL/SQL procedure successfully completed. --再次查詢 select client_name,status from Dba_Autotask_Client where client_name='auto optimizer stats collection'; CLIENT_NAME STATUS ---------------------------------------------------------------- -------- auto optimizer stats collection DISABLED
但是此時再查詢DBA_ATUOTASK_TASK檢視時,顯示該任務狀態還是ENABLED
select client_name,status from dba_autotask_task where client_name='auto optimizer stats collection'; CLIENT_NAME STATUS ---------------------------------------------------------------- -------- auto optimizer stats collection ENABLED
Oracle給出的解釋是在現在的版本中(11.1 to 11.2)一個client對應一個task,但是在將來的版本中會出現多個client會對應一個task,所以一個client被disabled了,不會改變task的狀態。[ID 858852.1]
3、啟動自動收集任務
BEGIN DBMS_AUTO_TASK_ADMIN.ENABLE( client_name => 'auto optimizer stats collection', operation => NULL, window_name => NULL); END; / PL/SQL procedure successfully completed. --再次查詢
select client_name,status from Dba_Autotask_Client where client_name='auto optimizer stats collection'; CLIENT_NAME STATUS ---------------------------------------------------------------- -------- auto optimizer stats collection ENABLED
4、檢視自動收集任務歷史執行狀態
SELECT client_name, window_name, jobs_created, jobs_started, jobs_completed FROM dba_autotask_client_history WHERE client_name like '%stats%';
CLIENT_NAME WINDOW_NAME JOBS_CREATED JOBS_STARTED JOBS_COMPLETED 1 auto optimizer stats collection FRIDAY_WINDOW 1 1 1 2 auto optimizer stats collection FRIDAY_WINDOW 1 1 1 3 auto optimizer stats collection FRIDAY_WINDOW 1 1 1 4 auto optimizer stats collection FRIDAY_WINDOW 1 1 1 5 auto optimizer stats collection MONDAY_WINDOW 1 1 1 6 auto optimizer stats collection MONDAY_WINDOW 1 1 1 7 auto optimizer stats collection MONDAY_WINDOW 1 1 1 8 auto optimizer stats collection MONDAY_WINDOW 1 1 1 9 auto optimizer stats collection SATURDAY_WINDOW 5 5 5 10 auto optimizer stats collection SATURDAY_WINDOW 5 5 5 11 auto optimizer stats collection SATURDAY_WINDOW 5 5 5 12 auto optimizer stats collection SATURDAY_WINDOW 5 5 5 13 auto optimizer stats collection SUNDAY_WINDOW 5 5 5 14 auto optimizer stats collection SUNDAY_WINDOW 5 5 5 15 auto optimizer stats collection SUNDAY_WINDOW 5 5 5 16 auto optimizer stats collection SUNDAY_WINDOW 5 5 5 17 auto optimizer stats collection THURSDAY_WINDOW 1 1 1 18 auto optimizer stats collection THURSDAY_WINDOW 1 1 1 19 auto optimizer stats collection THURSDAY_WINDOW 1 1 1 20 auto optimizer stats collection THURSDAY_WINDOW 1 1 1 21 auto optimizer stats collection TUESDAY_WINDOW 1 1 1 22 auto optimizer stats collection TUESDAY_WINDOW 1 1 1 23 auto optimizer stats collection TUESDAY_WINDOW 1 1 1 24 auto optimizer stats collection TUESDAY_WINDOW 1 1 1 25 auto optimizer stats collection TUESDAY_WINDOW 1 1 1 26 auto optimizer stats collection WEDNESDAY_WINDOW 1 1 1 27 auto optimizer stats collection WEDNESDAY_WINDOW 1 1 1 28 auto optimizer stats collection WEDNESDAY_WINDOW 1 1 1 29 auto optimizer stats collection WEDNESDAY_WINDOW 1 1 1 30 auto optimizer stats collection WEDNESDAY_WINDOW 1 1 1
透過時間視窗名稱可以看出是周幾執行的,在時間視窗內建立了幾次job,執行了幾次job,當然可以加上window_start_time來檢視具體執行的日期。
5、檢視自動收集任務執行時間視窗
select WINDOW_NAME, WINDOW_NEXT_TIME , WINDOW_ACTIVE,OPTIMIZER_STATS from DBA_AUTOTASK_WINDOW_CLIENTS order by WINDOW_NEXT_TIME ;
WINDOW_NAME WINDOW_NEXT_TIME WINDOW_ACTIVE OPTIMIZER_STATS 1 THURSDAY_WINDOW 07-AUG-14 10.00.00.000000 PM +08:00 FALSE ENABLED 2 FRIDAY_WINDOW 08-AUG-14 10.00.00.000000 PM +08:00 FALSE ENABLED 3 SATURDAY_WINDOW 09-AUG-14 06.00.00.000000 AM +08:00 FALSE ENABLED 4 SUNDAY_WINDOW 10-AUG-14 06.00.00.000000 AM +08:00 FALSE ENABLED 5 MONDAY_WINDOW 11-AUG-14 10.00.00.000000 PM +08:00 FALSE ENABLED 6 TUESDAY_WINDOW 12-AUG-14 10.00.00.000000 PM +08:00 FALSE ENABLED 7 WEDNESDAY_WINDOW 13-AUG-14 10.00.00.000000 PM +08:00 FALSE ENABLED
6、查詢自動收集任務正在執行的JOB
select client_name, JOB_SCHEDULER_STATUS from DBA_AUTOTASK_CLIENT_JOB where client_name='auto optimizer stats collection';
這個查詢沒有結果也很正常,只有job正在執行時,該查詢才有結果。
7、與時間視窗相關的檢視
查詢自動收集任務所屬時間視窗組
select client_name,window_group from dba_autotask_client where client_name='auto optimizer stats collection';
CLIENT_NAME WINDOW_GROUP 1 auto optimizer stats collection ORA$AT_WGRP_OS
查詢自動收集任務所屬時間視窗組詳細資訊
select * from dba_scheduler_window_groups where window_group_name='ORA$AT_WGRP_OS';
WINDOW_GROUP_NAME ENABLED NUMBER_OF_WINDOWS NEXT_START_DATE COMMENTS 1 ORA$AT_WGRP_OS TRUE 7 07-AUG-14 10.00.00.000000 PM +08:00 auto optimizer stats collection
檢視自動收集任務所屬時間視窗組包含的子時間視窗
select * from dba_scheduler_wingroup_members where window_group_name='ORA$AT_WGRP_OS';
WINDOW_GROUP_NAME WINDOW_NAME 1 ORA$AT_WGRP_OS MONDAY_WINDOW 2 ORA$AT_WGRP_OS TUESDAY_WINDOW 3 ORA$AT_WGRP_OS WEDNESDAY_WINDOW 4 ORA$AT_WGRP_OS THURSDAY_WINDOW 5 ORA$AT_WGRP_OS FRIDAY_WINDOW 6 ORA$AT_WGRP_OS SATURDAY_WINDOW 7 ORA$AT_WGRP_OS SUNDAY_WINDOW
檢視子時間視窗資訊
select a.window_name,a.next_start_date,a.active from dba_scheduler_windows a inner join dba_scheduler_wingroup_members b on a.window_name = b.window_name where b.window_group_name='ORA$AT_WGRP_OS';
WINDOW_NAME NEXT_START_DATE ACTIVE 1 MONDAY_WINDOW 11-AUG-14 10.00.00.000000 PM +08:00 FALSE 2 TUESDAY_WINDOW 12-AUG-14 10.00.00.000000 PM +08:00 FALSE 3 WEDNESDAY_WINDOW 13-AUG-14 10.00.00.000000 PM +08:00 FALSE 4 THURSDAY_WINDOW 07-AUG-14 10.00.00.000000 PM +08:00 FALSE 5 FRIDAY_WINDOW 08-AUG-14 10.00.00.000000 PM +08:00 FALSE 6 SATURDAY_WINDOW 09-AUG-14 06.00.00.000000 AM +08:00 FALSE 7 SUNDAY_WINDOW 10-AUG-14 06.00.00.000000 AM +08:00 FALSE
透過這個查詢可以看出DBA_AUTOTASK_WINDOW_CLIENTS檢視的資訊其實和上面的結果一樣。
總結一下統計資訊自動收集任務執行的步驟:
首先是dba_autotask_task-->dba_autotask_client建立自動執行任務
再根據時間視窗及資源組建立自動執行作業
dba_autotask_client-->dba_scheduler_window_groups-->dba_scheduler_windows-->dba_scheduler_jobs
dba_autotask_client-->dba_scheduler_job_classes
相關檢視:
dba_autotask_task
dba_autotask_client
dba_autotask_client_job
dba_autotask_window_clients
dba_autotask_client_history
dba_scheduler_jobs
dba_scheduler_job_classes
dba_scheduler_window_groups
dba_scheduler_windows
dba_scheduler_wingroup_members
自定義自動收集任務時間視窗:
How to use an own Maintenance Window for the Statistics Collection in 11g [ID 1300313.1]
MOS相關文件: FAQ: Automatic Statistics Collection [ID 1233203.1]