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
有一定的区别,暂时还未测试。
9、开启和关闭统计信息的自动收集任务
--关闭信息自动收集任务 BEGIN DBMS_AUTO_TASK_ADMIN.DISABLE( client_name => 'auto optimizer stats collection', operation => NULL, window_name => NULL); END; / PL/SQL procedure successfully completed. 开启和关闭单个时间窗口:
BEGIN
DBMS_AUTO_TASK_ADMIN.disable (
client_name => 'auto optimizer stats collection',
operation => NULL,
window_name => 'MONDAY_WINDOW');
END;
/
统计信息自动收集任务运行的步骤:
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]
参考素材:https://www.cnblogs.com/xwdreamer/p/3897580.html