标签:
一、Oracle 11g
在Oracle的11g版本中提供了统计数据自动收集的功能。在部署安装11g Oracle软件过程中,其中有一个步骤便是提示是否启动这个功能(默认是启用这个功能)。
在这里介绍一下怎么将该功能启用与禁用:
1、查看自动收集统计信息的任务及状态:
SQL> select client_name,status from dba_autotask_client; CLIENT_NAME STATUS ---------------------------------------- ---------------- auto optimizer stats collection ENABLED auto space advisor ENABLED sql tuning advisor ENABLED 其中"auto optimizer stats collection"便是我们要寻找的自动收集统计信息的任务名称,它的状态目前是启用状态。
2、禁止自动收集统计信息的任务
禁用自动收集统计信息的任务可以使用DBMS_AUTO_TASK_ADMIN包完成: SQL> exec DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => ‘auto optimizer stats collection‘,operation => NULL,window_name => NULL); PL/SQL 过程已成功完成。 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 此时"auto optimizer stats collection"任务已经被禁用。
3、启用自动收集统计信息的任务
SQL> exec DBMS_AUTO_TASK_ADMIN.ENABLE(client_name => ‘auto optimizer stats collection‘,operation => NULL,window_name => NULL); PL/SQL 过程已成功完成。 SQL> select client_name,status from dba_autotask_client; CLIENT_NAME STATUS ---------------------------------------- ---------------- auto optimizer stats collection ENABLED auto space advisor ENABLED sql tuning advisor ENABLED
这个功能貌似带来了统计数据采集上的便捷,但是Oracle 11g自动收集统计信息的时间是22:00--2:00
这个时间段往往是业务的高峰期,给本已紧张的系统带来更大的负担。所以,应该把自动执行的时间改到空闲的时段。
4、获得当前自动收集统计信息的执行时间:
SQL> select t1.window_name,t1.repeat_interval,t1.duration from dba_scheduler_windows t1,dba_scheduler_wingroup_members t2 2 where t1.window_name=t2.window_name and t2.window_group_name in (‘MAINTENANCE_WINDOW_GROUP‘,‘BSLN_MAINTAIN_STATS_SCHED‘); WINDOW_NAME REPEAT_INTERVAL DURATION ------------------------------ -------------------------------------------------------------------------------- ------------------------------------------------------------------------------- MONDAY_WINDOW freq=daily;byday=MON;byhour=22;byminute=0; bysecond=0 +000 04:00:00 TUESDAY_WINDOW freq=daily;byday=TUE;byhour=22;byminute=0; bysecond=0 +000 04:00:00 WEDNESDAY_WINDOW freq=daily;byday=WED;byhour=22;byminute=0; bysecond=0 +000 04:00:00 THURSDAY_WINDOW freq=daily;byday=THU;byhour=22;byminute=0; bysecond=0 +000 04:00:00 FRIDAY_WINDOW freq=daily;byday=FRI;byhour=22;byminute=0; bysecond=0 +000 04:00:00 SATURDAY_WINDOW freq=daily;byday=SAT;byhour=6;byminute=0; bysecond=0 +000 20:00:00 SUNDAY_WINDOW freq=daily;byday=SUN;byhour=6;byminute=0; bysecond=0 +000 20:00:00 7 rows selected
其中:
WINDOW_NAME:任务名
REPEAT_INTERVAL:任务重复间隔时间
DURATION:持续时间
修改步骤如下:
1.停止任务: SQL> BEGIN 2 DBMS_SCHEDULER.DISABLE( 3 name => ‘"SYS"."FRIDAY_WINDOW"‘, 4 force => TRUE); 5 END; 6 / PL/SQL 过程已成功完成。 2.修改任务的持续时间,单位是分钟: SQL> BEGIN 2 DBMS_SCHEDULER.SET_ATTRIBUTE( 3 name => ‘"SYS"."FRIDAY_WINDOW"‘, 4 attribute => ‘DURATION‘, 5 value => numtodsinterval(180,‘minute‘)); 6 END; 7 / PL/SQL 过程已成功完成。 3.开始执行时间,BYHOUR=2,表示2点开始执行: SQL> BEGIN 2 DBMS_SCHEDULER.SET_ATTRIBUTE( 3 name => ‘"SYS"."FRIDAY_WINDOW"‘, 4 attribute => ‘REPEAT_INTERVAL‘, 5 value => ‘FREQ=WEEKLY;BYDAY=MON;BYHOUR=2;BYMINUTE=0;BYSECOND=0‘); 6 END; 7 / PL/SQL 过程已成功完成。 4.开启任务: SQL> BEGIN 2 DBMS_SCHEDULER.ENABLE( 3 name => ‘"SYS"."FRIDAY_WINDOW"‘); 4 END; 5 / PL/SQL 过程已成功完成。 5.查看修改后的情况: SQL> select t1.window_name,t1.repeat_interval,t1.duration from dba_scheduler_windows t1,dba_scheduler_wingroup_members t2 2 where t1.window_name=t2.window_name and t2.window_group_name in (‘MAINTENANCE_WINDOW_GROUP‘,‘BSLN_MAINTAIN_STATS_SCHED‘); WINDOW_NAME REPEAT_INTERVAL DURATION ------------------------------ -------------------------------------------------------------------------------- ------------------------------------------------------------------------------- WEDNESDAY_WINDOW freq=daily;byday=WED;byhour=22;byminute=0; bysecond=0 +000 04:00:00 FRIDAY_WINDOW FREQ=WEEKLY;BYDAY=MON;BYHOUR=2;BYMINUTE=0;BYSECOND=0 +000 03:00:00 SATURDAY_WINDOW freq=daily;byday=SAT;byhour=6;byminute=0; bysecond=0 +000 20:00:00 THURSDAY_WINDOW freq=daily;byday=THU;byhour=22;byminute=0; bysecond=0 +000 04:00:00 TUESDAY_WINDOW freq=daily;byday=TUE;byhour=22;byminute=0; bysecond=0 +000 04:00:00 SUNDAY_WINDOW freq=daily;byday=SUN;byhour=6;byminute=0; bysecond=0 +000 20:00:00 MONDAY_WINDOW freq=daily;byday=MON;byhour=22;byminute=0; bysecond=0 +000 04:00:00 7 rows selected
标签:
原文地址:http://www.cnblogs.com/snailwong/p/5904056.html