博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Oracle] 11G自己主动收集统计信息
阅读量:5909 次
发布时间:2019-06-19

本文共 5323 字,大约阅读时间需要 17 分钟。

在11g中,默认自己主动收集统计信息的时间为晚上10点(周一到周五,4个小时),早上6点(周六,周日,20个小时),例如以下所看到的:

select a.window_name, a.repeat_interval,a.duration  from dba_scheduler_windows a, dba_scheduler_wingroup_members b  where a.window_name = b.window_name    and b.window_group_name = 'MAINTENANCE_WINDOW_GROUP';WINDOW_NAME                    REPEAT_INTERVAL                                              DURATION------------------------------ ------------------------------------------------------------ --------------------WEDNESDAY_WINDOW               freq=daily;byday=WED;byhour=22;byminute=0; bysecond=0        +000 04:00:00FRIDAY_WINDOW                  freq=daily;byday=FRI;byhour=22;byminute=0; bysecond=0        +000 04:00:00SATURDAY_WINDOW                freq=daily;byday=SAT;byhour=6;byminute=0; bysecond=0         +000 20:00:00THURSDAY_WINDOW                freq=daily;byday=THU;byhour=22;byminute=0; bysecond=0        +000 04:00:00TUESDAY_WINDOW                 freq=daily;byday=TUE;byhour=22;byminute=0; bysecond=0        +000 04:00:00SUNDAY_WINDOW                  freq=daily;byday=SUN;byhour=6;byminute=0; bysecond=0         +000 20:00:00MONDAY_WINDOW                  freq=daily;byday=MON;byhour=22;byminute=0; bysecond=0        +000 04:00:00
因为非常多系统晚上10点还是处于业务高峰期,因此有必要调整下时间,这个要依据各自的业务自己推断,在我们系统调为:

周一到周五,凌晨1点開始,持续5个小时; 周六、周日,凌晨1点開始,持续10个小时。

用sys用户运行例如以下语句就可以:

begin  sys.dbms_scheduler.set_attribute(name => 'SYS.MONDAY_WINDOW', attribute => 'repeat_interval', value => 'freq=daily;byday=MON;byhour=1;byminute=0; bysecond=0');  sys.dbms_scheduler.set_attribute(name => 'SYS.MONDAY_WINDOW', attribute => 'duration', value => '0 05:00:00');end;/begin  sys.dbms_scheduler.set_attribute(name => 'SYS.TUESDAY_WINDOW', attribute => 'repeat_interval', value => 'freq=daily;byday=TUE;byhour=1;byminute=0; bysecond=0');  sys.dbms_scheduler.set_attribute(name => 'SYS.TUESDAY_WINDOW', attribute => 'duration', value => '0 05:00:00');end;/begin  sys.dbms_scheduler.set_attribute(name => 'SYS.WEDNESDAY_WINDOW', attribute => 'repeat_interval', value => 'freq=daily;byday=WED;byhour=1;byminute=0; bysecond=0');  sys.dbms_scheduler.set_attribute(name => 'SYS.WEDNESDAY_WINDOW', attribute => 'duration', value => '0 05:00:00');end;/begin  sys.dbms_scheduler.set_attribute(name => 'SYS.THURSDAY_WINDOW', attribute => 'repeat_interval', value => 'freq=daily;byday=THU;byhour=1;byminute=0; bysecond=0');  sys.dbms_scheduler.set_attribute(name => 'SYS.THURSDAY_WINDOW', attribute => 'duration', value => '0 05:00:00');end;/begin  sys.dbms_scheduler.set_attribute(name => 'SYS.FRIDAY_WINDOW', attribute => 'repeat_interval', value => 'freq=daily;byday=FRI;byhour=1;byminute=0; bysecond=0');  sys.dbms_scheduler.set_attribute(name => 'SYS.FRIDAY_WINDOW', attribute => 'duration', value => '0 05:00:00');end;/begin  sys.dbms_scheduler.set_attribute(name => 'SYS.SATURDAY_WINDOW', attribute => 'repeat_interval', value => 'freq=daily;byday=SAT;byhour=1;byminute=0; bysecond=0');  sys.dbms_scheduler.set_attribute(name => 'SYS.SATURDAY_WINDOW', attribute => 'duration', value => '0 10:00:00');end;/begin  sys.dbms_scheduler.set_attribute(name => 'SYS.SUNDAY_WINDOW', attribute => 'repeat_interval', value => 'freq=daily;byday=SUN;byhour=1;byminute=0; bysecond=0');  sys.dbms_scheduler.set_attribute(name => 'SYS.SUNDAY_WINDOW', attribute => 'duration', value => '0 10:00:00');end;/
上面语句运行成功后的结果例如以下:

WINDOW_NAME                    REPEAT_INTERVAL                                              DURATION------------------------------ ------------------------------------------------------------ --------------------WEDNESDAY_WINDOW               freq=daily;byday=WED;byhour=1;byminute=0; bysecond=0         +000 05:00:00FRIDAY_WINDOW                  freq=daily;byday=FRI;byhour=1;byminute=0; bysecond=0         +000 05:00:00SATURDAY_WINDOW                freq=daily;byday=SAT;byhour=1;byminute=0; bysecond=0         +000 10:00:00THURSDAY_WINDOW                freq=daily;byday=THU;byhour=1;byminute=0; bysecond=0         +000 05:00:00TUESDAY_WINDOW                 freq=daily;byday=TUE;byhour=1;byminute=0; bysecond=0         +000 05:00:00SUNDAY_WINDOW                  freq=daily;byday=SUN;byhour=1;byminute=0; bysecond=0         +000 10:00:00MONDAY_WINDOW                  freq=daily;byday=MON;byhour=1;byminute=0; bysecond=0         +000 05:00:00
时间调整成功后,下一步就是开启11G的自己主动收集统计信息job,首先确认当前未开启:

SYS@PROD> select client_name,status from DBA_AUTOTASK_CLIENT where client_name='auto optimizer stats collection';CLIENT_NAME                                                      STATUS---------------------------------------------------------------- --------auto optimizer stats collection                                  DISABLED
运行例如以下语句开启:

BEGIN  dbms_auto_task_admin.enable(  client_name => 'auto optimizer stats collection',  operation => NULL,  window_name => NULL);END;/
确认已被开启:

SYS@PROD> select client_name,status from DBA_AUTOTASK_CLIENT where client_name='auto optimizer stats collection';CLIENT_NAME                                                      STATUS---------------------------------------------------------------- --------auto optimizer stats collection                                  ENABLED
附:关闭这个job的语句:

BEGIN   dbms_auto_task_admin.disable(   client_name => 'auto optimizer stats collection',   operation => NULL,   window_name => NULL); END;  /

转载地址:http://tlppx.baihongyu.com/

你可能感兴趣的文章
SQL Server中DateTime与DateTime2的区别
查看>>
Codekit - 为Web前端打造的全能型神器(附推荐各种工具)
查看>>
java 截取字符串 拆分字符串
查看>>
从零开始学C++之数据封装与抽象:分别用C和C++来实现一个链栈
查看>>
[置顶] IT老男人读《因为痛,所以叫青春》
查看>>
Android NDK学习(3)使用Javah命令生成JNI头文件 .
查看>>
poj2186Popular Cows(Kosaraju算法--有向图的强连通分量的分解)
查看>>
LR基础学习_脚本信息函数
查看>>
基于html5 canvas和js实现的水果忍者网页版
查看>>
2、传统的线程互斥synchronized
查看>>
IT忍者神龟之使用 PowerDesigner
查看>>
JSP导出Excel文件
查看>>
谷歌大神Jeff Dean:大规模深度学习最新进展 zz
查看>>
javaweb学习总结(八)——HttpServletResponse对象(二)
查看>>
CSharpGL(24)用ComputeShader实现一个简单的图像边缘检测功能
查看>>
jquery------提供灵活的方法参数
查看>>
Android ContentProvider和getContentResolver
查看>>
深入理解javascript描述元素内容的5个属性
查看>>
Android 知识梳理
查看>>
poj 1331 Multiply
查看>>