自动维护任务是一种按规则自动启动的数据库维护操作任务。比如自动收集为查询优化器使用的统计信息。自动维护任务按维护窗口自动运
行。所谓自动维护窗口是按照预定义的间隔时间窗口。
oracle11g数据库有三种预定义的自动维护任务:
■ Automatic OptimizerStatistics Collection:
■ Automatic SegmentAdvisor
■ Automatic SQLTuning Advisor(这个是oracle 11g新添加的自动维护任务)
缺省情况下,这三个任务配置为在所有维护窗口运行。
维护窗口:维护窗口是一个连续的时间间隔,用于管理自动维护任务所用。维护窗口是oracle调度窗口,属于窗口组MAINTENANCE_WINDOW_GROUP。
Oracle 11g 数据库有三个预定义自动维护任务:
Automatic Optimizer Statistics Collection(自动优化器统计信息收集)
收集数据库中所有无统计信息或仅有过时统计信息的 Schema 对象的 Optimizer(优化器)统计信息。SQL query optimizer(SQL 查询优化器)使用此任务收集的统计信息提高 SQL 执行的性能。
Automatic Segment Advisor(自动段指导)
识别有可用回收空间的段,并提出如何消除这些段中的碎片的建议。您也可以手动运行 Segment Advisor 获取更多最新建议,或获取 Automatic SegmentAdvisor 没有检查到的那些有可能做空间回收的段的建议。
Automatic SQL Tuning Advisor(自动 SQL 优化指导)
检查高负载 SQL 语句的性能,并提出如何优化这些语句的建议。您可以配置此指导,自动应用建议的SQL profile。
一:配置自动维护任务:
1:启用和禁止维护任务:
使用DBMS_AUTO_TASK_ADMIN pl/sql包来启用或禁用任务:
禁用任务:
BEGIN
dbms_auto_task_admin.disable(
client_name => 'sql tuning advisor',
operation => NULL,
window_name => NULL);
END;
启用任务:
BEGIN
dbms_auto_task_admin.enable(
client_name => 'sql tuning advisor',
operation => NULL,
window_name => NULL);
END;
这里client_name参数可以通过数据字典视图DBA_AUTOTASK_CLIENT来查询。
SQL> desc DBA_AUTOTASK_CLIENT
名称 是否为空?类型
------------------------------------------------- ----------------------------
CLIENT_NAME VARCHAR2(64)
STATUS VARCHAR2(8)
CONSUMER_GROUP VARCHAR2(30)
CLIENT_TAG VARCHAR2(2)
PRIORITY_OVERRIDE VARCHAR2(7)
ATTRIBUTES VARCHAR2(4000)
WINDOW_GROUP VARCHAR2(64)
SERVICE_NAME VARCHAR2(64)
RESOURCE_PERCENTAGE NUMBER
USE_RESOURCE_ESTIMATES VARCHAR2(5)
MEAN_JOB_DURATION INTERVALDAY(9) TO SECOND(9)
MEAN_JOB_CPU INTERVALDAY(9) TO SECOND(9)
MEAN_JOB_ATTEMPTS NUMBER
MEAN_INCOMING_TASKS_7_DAYS NUMBER
MEAN_INCOMING_TASKS_30_DAYS NUMBER
TOTAL_CPU_LAST_7_DAYS INTERVAL DAY(9)TO SECOND(9)
TOTAL_CPU_LAST_30_DAYS INTERVAL DAY(9) TOSECOND(9)
MAX_DURATION_LAST_7_DAYS INTERVAL DAY(3) TOSECOND(0)
MAX_DURATION_LAST_30_DAYS INTERVAL DAY(3) TOSECOND(0)
WINDOW_DURATION_LAST_7_DAYS INTERVAL DAY(9) TOSECOND(9)
WINDOW_DURATION_LAST_30_DAYS INTERVAL DAY(9) TOSECOND(9)
SQL> select client_name fromDBA_AUTOTASK_CLIENT;
CLIENT_NAME
----------------------------------------------------------------
auto optimizerstats collection
auto spaceadvisor
sql tuningadvisor
如果想启用或禁用所有窗口自动维护任务,调用ENABLE或DISABLE过程:
EXECUTE DBMS_AUTO_TASK_ADMIN.DISABLE;
2:为某一个维护窗口启用或禁用维护窗口
缺省情况下,所有维护任务在所有预定义的维护窗口都运行。可以对某一个维护窗口启用或禁用自动化任务。
BEGIN
dbms_auto_task_admin.disable(
client_name => 'sql tuning advisor',
operation => NULL,
window_name => 'MONDAY_WINDOW');
END;
上面的例子是对维护窗口monday_window进行禁用sqltuning advisor。
二:配置维护窗口:
可是使用DBMS_SCHEDULER包来修改窗口属性。
1:修改维护窗口
--先禁用维护窗口
BEGIN
dbms_scheduler.disable(
name => 'SATURDAY_WINDOW');
--修改维护窗口属性:
dbms_scheduler.set_attribute(
name => 'SATURDAY_WINDOW',
attribute => 'DURATION',
value => numtodsinterval(4, 'hour'));
--启用维护窗口
dbms_scheduler.enable(
name => 'SATURDAY_WINDOW');
END;
/
对于当前打开的窗口,你需要首先禁用,然后修改再启用,配置立即生效,如果你不通过这三个过程来修改属性,属性是不会生效的,直到下一次窗口打开。
2:创建新窗口:
BEGIN
dbms_scheduler.create_window(
window_name => 'EARLY_MORNING_WINDOW',
duration => numtodsinterval(1, 'hour'),
resource_plan => 'DEFAULT_MAINTENANCE_PLAN',
repeat_interval =>'FREQ=DAILY;BYHOUR=5;BYMINUTE=0;BYSECOND=0');
dbms_scheduler.add_window_group_member(
group_name => 'MAINTENANCE_WINDOW_GROUP',
window_list => 'EARLY_MORNING_WINDOW');
END;
/
3:删除窗口:
BEGIN
DBMS_SCHEDULER.REMOVE_WINDOW_GROUP_MEMBER(
group_name => 'MAINTENANCE_WINDOW_GROUP',
window_list => 'EARLY_MORNING_WINDOW');
END;
/
三:跟踪job运行情况:
可以通过查询视图DBA_AUTOTASK_HISTORY追踪job运行情况:
SQL> selectclient_name,job_name,job_start_time
fromdba_autotask_job_history;
CLIENT_NAME JOB_NAMEJOB_START_TIME
---------------------------------------- ------------------------------------
auto optimizer statsORA$AT_OS_OPT_SY_1 09-APR-12 10.00.02.039000 PM +08:00
auto space advisorORA$AT_SA_SPC_SY_2 09-APR-12 10.00.02.050000 PM +08:00
sql tuning advisorORA$AT_SQ_SQL_SW_3 09-APR-12 10.00.02.015000 PM +08:00
四,为自动维护任务配置资源分配
默认的,所有的预定义的维护窗口使用资源计划DEFAULT_MAINTENANCE_PLAN
DEFAULT_MAINTENANCE_PLAN 定义了下面的资源分配:
mer Group/subplan |
Level 1 |
Level 2 |
Maximum Utilization Limit |
ORA$AUTOTASK_SUB_PLAN |
- |
25% |
90 |
ORA$DIAGNOSTICS |
- |
5% |
90 |
OTHER_GROUPS |
- |
70% |
|
SYS_GROUP |
75% |
- |
|
五,自动维护任务参考
预定义的维护窗口
Window Name |
Description |
MONDAY_WINDOW |
Starts at 10 p.m. on Monday and ends at 2 a.m. |
TUESDAY_WINDOW |
Starts at 10 p.m. on Tuesday and ends at 2 a.m. |
WEDNESDAY_WINDOW |
Starts at 10 p.m. on Wednesday and ends at 2 a.m. |
THURSDAY_WINDOW |
Starts at 10 p.m. on Thursday and ends at 2 a.m. |
FRIDAY_WINDOW |
Starts at 10 p.m. on Friday and ends at 2 a.m. |
SATURDAY_WINDOW |
Starts at 6 a.m. on Saturday and is 20 hours long. |
SUNDAY_WINDOW |
Starts at 6 a.m. on Sunday and is 20 hours long. |
视图:
SQL> descDBA_AUTOTASK_WINDOW_CLIENTS
Name Null? Type
------------------------------------------------- ----------------------------
WINDOW_NAME NOT NULLVARCHAR2(30)
WINDOW_NEXT_TIME TIMESTAMP(6)WITH TIME ZONE
WINDOW_ACTIVE VARCHAR2(5)
AUTOTASK_STATUS VARCHAR2(8)
OPTIMIZER_STATS VARCHAR2(8)
SEGMENT_ADVISOR VARCHAR2(8)
SQL_TUNE_ADVISOR VARCHAR2(8)
HEALTH_MONITOR VARCHAR2(8)
SQL> select *from DBA_AUTOTASK_WINDOW_CLIENTS;
WINDOW_NAME WINDOW_NEXT_TIME WINDO AUTOTASKOPTIMIZE SEGMENT_ SQL_TUNE HEALTH_M
---------------------------------------------------------------------- ----- -------- -------- ---------------- --------
WEDNESDAY_WINDOW 11-SEP-13 10.00.00.000000 PMPRC FALSE ENABLED ENABLED ENABLED ENABLED DISABLED
SATURDAY_WINDOW 14-SEP-13 06.00.00.000000 AMPRC FALSE ENABLED ENABLED ENABLED ENABLED DISABLED
THURSDAY_WINDOW 12-SEP-13 10.00.00.000000 PMPRC FALSE ENABLED ENABLED ENABLED ENABLED DISABLED
TUESDAY_WINDOW 17-SEP-13 10.00.00.000000 PMPRC FALSE ENABLED ENABLED ENABLED ENABLED DISABLED
SUNDAY_WINDOW 15-SEP-13 06.00.00.000000 AMPRC FALSE ENABLED ENABLED ENABLED ENABLED DISABLED
MONDAY_WINDOW 16-SEP-13 10.00.00.000000 PMPRC FALSE ENABLED ENABLED ENABLED ENABLED DISABLED
FRIDAY_WINDOW 13-SEP-13 10.00.00.000000 PMPRC FALSE ENABLED ENABLED ENABLED ENABLED DISABLED
7 rows selected.
相关视图:
View Name |
Description |
DBA_AUTOTASK_CLIENT_JOB |
Contains information about currently running Scheduler jobs created for automated maintenance tasks. It provides information about some objects targeted by those jobs, as well as some additional statistics from previous instantiations of the same task. Some of this additional data is taken from generic Scheduler views. |
DBA_AUTOTASK_CLIENT |
Provides statistical data for each automated maintenance task over 7-day and 30-day periods. |
DBA_AUTOTASK_JOB_HISTORY |
Lists the history of automated maintenance task job runs. Jobs are added to this view after they finish executing. |
DBA_AUTOTASK_WINDOW_CLIENTS |
Lists the windows that belong to MAINTENANCE_WINDOW_GROUP, along with the Enabled or Disabled status for the window for each maintenance task. Primarily used by Enterprise Manager. |
DBA_AUTOTASK_CLIENT_HISTORY |
Provides per-window history of job execution counts for each automated maintenance task. This information is viewable in the Job History page of Enterprise Manager. |
六,10g与11g之间的变化摘要
10g 与 11g 之间变化的摘要:
主题 |
10g |
11g |
作业 |
在 DBA_SCHEDULER_JOBS 中独立作业 |
AUTOTASKS 有命名前缀“ORA$AT”,且只有作业执行后才可见 |
维护窗口 |
2 个窗口:WEEKNIGHT 和 WEEKEND |
每天有不同的窗口 |
Resource manager |
默认不启用 |
每个窗口都有预定义资源计划 |
相关视图:
DBA_AUTOTASK_CLIENT
DBA_AUTOTASK_CLIENT_HISTORY
DBA_AUTOTASK_CLIENT_JOB
DBA_AUTOTASK_JOB_HISTORY
DBA_AUTOTASK_OPERATION
DBA_AUTOTASK_SCHEDULE
DBA_AUTOTASK_TASK
DBA_AUTOTASK_WINDOW_CLIENTS
DBA_AUTOTASK_WINDOW_HISTORY