ORACLE 11G 自動收集

不一樣的天空w發表於2017-01-23

11g中統計資訊自動收集任務的名稱是auto optimizer stats collection。11g中自動任務預設的執行時間視窗為:
    週一到週五是晚上10點開始到2點結束
    週末是早上六點,持續20個小時。
1、檢視自動收集任務及狀態

select client_name,status from Dba_Autotask_Client where client_name='auto optimizer stats collection';

2、停止自動收集任務

SQL> BEGIN
  2      DBMS_AUTO_TASK_ADMIN.DISABLE(
  3                     client_name => 'auto optimizer stats collection',
  4                     operation => NULL, window_name => NULL);
  5  END;
  6  /
 
PL/SQL procedure successfully completed.
SQL> 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

SQL> 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、啟動自動收集任務

SQL> BEGIN
  2      DBMS_AUTO_TASK_ADMIN.ENABLE(
  3                     client_name => 'auto optimizer stats collection',
  4                     operation => NULL, window_name => NULL);
  5  END;
  6  /
PL/SQL procedure successfully completed.
SQL> select client_name,status from Dba_Autotask_Client where client_name='auto optimizer stats collection';
CLIENT_NAME                                                      STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection                                  ENABLED 

4、檢視自動收集任務歷史執行狀態

 SQL> SELECT client_name, window_name, jobs_created, jobs_started, jobs_completed
  2   FROM dba_autotask_client_history
  3   WHERE client_name like '%stats%';
CLIENT_NAME                              WINDOW_NAME                    JOBS_CREATED JOBS_STARTED JOBS_COMPLETED
---------------------------------------- ------------------------------ ------------ ------------ --------------
auto optimizer stats collection          SATURDAY_WINDOW                           5            5              5
auto optimizer stats collection          SUNDAY_WINDOW                             6            6              6

透過時間視窗名稱可以看出是周幾執行的,在時間視窗內建立了幾次job,執行了幾次job,當然可以加上window_start_time來檢視具體執行的日期。
5、檢視自動收集任務執行時間視窗


		

SQL> 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                                WINDO OPTIMIZE ------------------------------ ----------------------------------------------- ----- -------- MONDAY_WINDOW                  26-NOV-12 10.00.00.000000 PM PRC                TRUE  ENABLED TUESDAY_WINDOW                 27-NOV-12 10.00.00.000000 PM PRC                FALSE ENABLED WEDNESDAY_WINDOW               28-NOV-12 10.00.00.000000 PM PRC                FALSE ENABLED THURSDAY_WINDOW                29-NOV-12 10.00.00.000000 PM PRC                FALSE ENABLED FRIDAY_WINDOW                  30-NOV-12 10.00.00.000000 PM PRC                FALSE ENABLED SATURDAY_WINDOW                01-DEC-12 06.00.00.000000 AM PRC                FALSE ENABLED SUNDAY_WINDOW                  02-DEC-12 06.00.00.000000 AM PRC                FALSE ENABLED

我將系統日期改為11月26日22點以後,MONDAY_WINDOW執行時間視窗自動啟用。
6、查詢自動收集任務正在執行的JOB

select client_name, JOB_SCHEDULER_STATUS from DBA_AUTOTASK_CLIENT_JOB where client_name='auto optimizer stats collection';

這個查詢沒有結果也很正常,只有job正在執行時,該查詢才有結果。
7、與時間視窗相關的檢視
查詢自動收集任務所屬時間視窗組

SQL> select client_name,window_group from dba_autotask_client where client_name='auto optimizer stats collection';
CLIENT_NAME                              WINDOW_GROUP
---------------------------------------- ---------------------------------------------------
auto optimizer stats collection          ORA$AT_WGRP_OS

查詢自動收集任務所屬時間視窗組詳細資訊

SQL> select * from dba_scheduler_window_groups where window_group_name='ORA$AT_WGRP_OS';
WINDOW_GROUP_NA ENABL NUMBER_OF_WINDOWS NEXT_START_DATE                     COMMENTS
--------------- ----- ----------------- ----------------------------------- ---------------------------------------------
ORA$AT_WGRP_OS  TRUE                  7 26-NOV-12 10.00.00.000000 PM PRC    auto optimizer stats collection

檢視自動收集任務所屬時間視窗組包含的子時間視窗

SQL> select * from dba_scheduler_wingroup_members where window_group_name='ORA$AT_WGRP_OS';
WINDOW_GROUP_NA WINDOW_NAME
--------------- ------------------------------
ORA$AT_WGRP_OS  MONDAY_WINDOW
ORA$AT_WGRP_OS  TUESDAY_WINDOW
ORA$AT_WGRP_OS  WEDNESDAY_WINDOW
ORA$AT_WGRP_OS  THURSDAY_WINDOW
ORA$AT_WGRP_OS  FRIDAY_WINDOW
ORA$AT_WGRP_OS  SATURDAY_WINDOW ORA$AT_WGRP_OS  SUNDAY_WINDOW

檢視子時間視窗資訊

SQL> select a.window_name,a.next_start_date,a.active from dba_scheduler_windows a
  2  inner join dba_scheduler_wingroup_members b on a.window_name = b.window_name
  3  where b.window_group_name='ORA$AT_WGRP_OS';
WINDOW_NAME                    NEXT_START_DATE                     ACTIV
------------------------------ ----------------------------------- -----
MONDAY_WINDOW                  26-NOV-12 10.00.00.000000 PM PRC    TRUE
TUESDAY_WINDOW                 27-NOV-12 10.00.00.000000 PM PRC    FALSE
WEDNESDAY_WINDOW               28-NOV-12 10.00.00.000000 PM PRC    FALSE
THURSDAY_WINDOW                29-NOV-12 10.00.00.000000 PM PRC    FALSE
FRIDAY_WINDOW                  30-NOV-12 10.00.00.000000 PM PRC    FALSE
SATURDAY_WINDOW                01-DEC-12 06.00.00.000000 AM PRC    FALSE
SUNDAY_WINDOW                  02-DEC-12 06.00.00.000000 AM PRC    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]

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31397003/viewspace-2132846/,如需轉載,請註明出處,否則將追究法律責任。

相關文章