码迷,mamicode.com
首页 > 数据库 > 详细

Oracle 11g 之自动收集统计信息

时间:2019-07-08 17:49:15      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:启动   isa   nta   一个   min   body   整理   oracle   line   

 

  在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                                               DISABLED

SQL> 
 

2、禁止自动收集统计信息的任务

 
SQL> exec DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => ‘auto optimizer stats collection‘,operation => NULL,window_name => NULL);

PL/SQL procedure successfully completed.

SQL> select client_name,status from dba_autotask_client;

CLIENT_NAME                                                      STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection                                  DISABLED
auto space advisor                                               ENABLED
sql tuning advisor                                               DISABLED

SQL> 
 

3、启用自动收集统计信息的任务

 
SQL> exec DBMS_AUTO_TASK_ADMIN.ENABLE(client_name => ‘auto optimizer stats collection‘,operation => NULL,window_name => NULL);

PL/SQL procedure successfully completed.

SQL> select client_name,status from dba_autotask_client;

CLIENT_NAME                                                      STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection                                  ENABLED
auto space advisor                                               ENABLED
sql tuning advisor                                               DISABLED

SQL>
 

4、获得当前自动收集统计信息的执行时间:

 
SQL> col  WINDOW_NAME format a20
SQL> col REPEAT_INTERVAL format a70
SQL> col DURATION format a20
SQL> set line 180
SQL> select t1.window_name,t1.repeat_interval,t1.duration 
  2  from dba_scheduler_windows t1,dba_scheduler_wingroup_members t2
  3  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
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
FRIDAY_WINDOW        freq=daily;byday=FRI;byhour=22;byminute=0; bysecond=0                  +000 04:00:00

7 rows selected.

SQL>
 

其中:WINDOW_NAME:任务名       REPEAT_INTERVAL:任务重复间隔时间      DURATION:持续时间

5.修改统计信息执行的时间:

 
1.停止任务:
SQL> BEGIN
  2    DBMS_SCHEDULER.DISABLE(
  3    name => ‘"SYS"."THURSDAY_WINDOW"‘,
  4    force => TRUE);  --停止任务是true
  5  END;
  6  /

SQL>


2.修改任务的持续时间,单位是分钟:
SQL> BEGIN
  2    DBMS_SCHEDULER.SET_ATTRIBUTE(
  3    name => ‘"SYS"."THURSDAY_WINDOW"‘,
  4    attribute => ‘DURATION‘,
  5    value => numtodsinterval(60,‘minute‘));
  6  END;
  7  /
SQL>

3.开始执行时间,BYHOUR=2,表示2点开始执行:
SQL> BEGIN
  2    DBMS_SCHEDULER.SET_ATTRIBUTE(
  3    name => ‘"SYS"."THURSDAY_WINDOW"‘,
  4    attribute => ‘REPEAT_INTERVAL‘,
  5    value => ‘freq=daily;byday=THU;byhour=10;byminute=40;bysecond=0‘);
  6  END;
  7  /

SQL> 


4.开启任务:
SQL> BEGIN
  2    DBMS_SCHEDULER.ENABLE(
  3    name => ‘"SYS"."THURSDAY_WINDOW"‘);
  4  END;
  5  /
SQL> 



5.查看修改后的情况:
SQL> select t1.window_name,t1.repeat_interval,t1.duration 
  2  from dba_scheduler_windows t1,dba_scheduler_wingroup_members t2
  3  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
SATURDAY_WINDOW      freq=daily;byday=SAT;byhour=6;byminute=0; bysecond=0                   +000 20:00:00
THURSDAY_WINDOW      freq=daily;byday=THU;byhour=10;byminute=40;bysecond=0                  +000 01: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
FRIDAY_WINDOW        freq=daily;byday=FRI;byhour=22;byminute=0; bysecond=0                  +000 04:00:00

SQL> 
 

6.查看统计信息执行的历史记录

 
--维护窗口组
select * from dba_scheduler_window_groups;
--维护窗口组对应窗口
select * from dba_scheduler_wingroup_members
--维护窗口历史信息
select* from dba_scheduler_windows

--查询自动收集任务正在执行的job 
select * from DBA_AUTOTASK_CLIENT_JOB;
--查询自动收集任务历史执行状态
select * from DBA_AUTOTASK_JOB_HISTORY;
select * from DBA_AUTOTASK_CLIENT_HISTORY; 
 

 

--整理自网络

Oracle 11g 之自动收集统计信息

标签:启动   isa   nta   一个   min   body   整理   oracle   line   

原文地址:https://www.cnblogs.com/liuys635/p/11152645.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!