Statistics automatically perform requires the following conditions are met:
-
dba_autotask_task 字段status值 ENABLED
-
dba_autotask_client status field value ENABLED
-
dba_autotask_window_clients 字段AUTOTASK_STATUS值 ENABLED OPTIMIZER_STATS值 ENABLED WINDOW_ACTIVE值 FALSE
- dba_scheduler_windows field value ENABLED TRUE field ACTIVE value FALSE field DURATION value is greater than 10 minutes
-
dba_scheduler_jobs field value ENABLED TRUE
To summarize the steps statistics collection task to run automatically:
The first is dba_autotask_task -> dba_autotask_client set up an automated task
And then set up an automated job based on the time window and Resource Group
dba_autotask_client-->dba_scheduler_window_groups-->dba_scheduler_windows-->dba_scheduler_jobs
dba_autotask_client-->dba_scheduler_job_classes
1, statistics on the implementation of the general task view view dba_autotask_task
2, the total process view call statistics view dba_scheduler_programs
3, the execution state dba_autotask_client statistics, can be modified by performing DBMS_AUTO_TASK_ADMIN packet, updates the status field and dba_autotask_window_clients dba_autotask_client of OPTIMIZER_STATS, SEGMENT_ADVISOR, SQL_TUNE_ADVISOR field.
1 BEGIN 2 DBMS_AUTO_TASK_ADMIN.enable(client_name => 'auto optimizer stats collection', 3 operation => NULL, 4 window_name => 'MONDAY_WINDOW'); 5 END; 6 7 BEGIN 8 DBMS_AUTO_TASK_ADMIN.disable(client_name => 'auto optimizer stats collection', 9 operation => NULL, 10 window_name => NULL); 11 END;
4. If you do DBMS_AUTO_TASK_ADMIN package without parameters, change dba_autotask_window_clients field of AUTOTASK_STATUS
1 BEGIN 2 DBMS_AUTO_TASK_ADMIN.enable(); 3 END; 4 BEGIN 5 DBMS_AUTO_TASK_ADMIN.disable(); 6 END;
5, various views dba_scheduler_windows perform detailed statistical information such as the attribute (the execution time, execution duration) can be provided by
1 --设置开始时间 2 BEGIN 3 DBMS_SCHEDULER.SET_ATTRIBUTE(name => '"SYS"."WEDNESDAY_WINDOW"', 4 attribute => 'REPEAT_INTERVAL', 5 value => 'freq=daily;byday=WED;byhour=07;byminute=46;bysecond=0'); 6 END; 7 --设置执行时长,如果设置值小于10分钟,统计信息貌似不能搜集 8 BEGIN 9 DBMS_SCHEDULER.SET_ATTRIBUTE(name => '"SYS"."WEDNESDAY_WINDOW"', 10 attribute => 'DURATION', 11 VALUE => '+000 00:20:00'); 12 END; 13 --禁用窗口,禁用后dba_autotask_window_clients视图相关信息消失 14 BEGIN 15 dbms_scheduler.disable(name => 'WEDNESDAY_WINDOW', force => TRUE); 16 END; 17 --启用窗口 18 BEGIN 19 dbms_scheduler.enable(name => 'WEDNESDAY_WINDOW'); 20 END; 21 --停止JOB 22 BEGIN 23 dbms_scheduler.stop_job('ORA$AUTOTASK_CLEAN'); 24 END; 25 --手动打开窗口 26 BEGIN 27 dbms_scheduler.open_window('WEDNESDAY_WINDOW'); 28 END; 29 --关闭窗口 30 BEGIN 31 dbms_scheduler.close_window('WEDNESDAY_WINDOW'); 32 END;
注:在窗口执行的过程中dba_scheduler_windows视图ACTIVE字段是true状态,dba_autotask_window_clients视图WINDOW_ACTIVE字段也只true状态
表统计信息收集标识:
一个表中被修改的行数超过stale_percent(缺省值10%)时就会认为这个表的统计数据过时了。oracle会监控所有表的DML活动并在SGA中进行记录。监控的信息会定时的刷新到磁盘且可以通过*_tab_modifications视图来查看。
也可以调用dbms_stats.flush_database_monitoring_info过程来手动刷新这些数据.如果想在查询时得到最新信息(在所有统计数据收集之前内部监控数据会被刷新).可以通过查询user_tab_statistics视图中的stale_stats列来查看哪个表的统计数据过时了。 表的stale_stats被设置为NO,统计数据是最新的.表的stale_stats被设置为YES,统计数据是过时的.表的stale_stats没有被设置说明丢失统计数据.