【11g】Managing Automated Database Maintenance Tasks

版权声明:所有文章禁止转载但是均可在生产中使用提高效率 https://blog.csdn.net/viviliving/article/details/88885712

Managing Automated Database Maintenance Tasks

Oracle数据库自动化了几个常见的维护任务,这些任务通常由数据库管理员执行。这些自动维护任务是在预期系统负载较轻时执行的。您可以启用和禁用各个维护任务,并可以配置这些任务何时运行以及分配了哪些资源分配

In this chapter:

Note:

本章解释如何使用PL/SQL包管理自动化维护任务。一种更简单的方法是使用Enterprise Manager的图形界面。

To manage automatic maintenance tasks with Enterprise Manager:

  1. Access the Database Home Page.

    See Oracle Database 2 Day DBA or the Oracle Enterprise Manager Grid Control online help for instructions.

  2. On the Database Home Page, click Server to display the Server page.

  3. Under the Oracle Scheduler section, click Automated Maintenance Tasks to configure maintenance tasks, or Windows to configure maintenance windows.

About Automated Maintenance Tasks

自动维护任务是定期自动启动的任务,用于对数据库执行维护操作。例如,一个任务为查询优化器收集模式对象的统计信息。自动维护任务在维护窗口中运行,维护窗口是预先定义的时间间隔,用于在系统负载较低期间执行。您可以根据数据库的资源使用模式自定义维护窗口,或者禁用某些默认窗口。您还可以创建自己的维护窗口。

Oracle数据库有三个预定义的自动维护任务:

  • 自动优化器统计信息收集—收集数据库中没有统计信息或只有陈旧统计信息的所有模式对象的优化器统计信息。SQL查询优化器使用此任务收集的统计信息来提高SQL执行的性能。

    See Also:

    Oracle Database Performance Tuning Guide for more information on automatic statistics collection
  • 自动分段顾问-识别有回收空间的分段,并就如何对这些分段进行碎片整理提出建议。
    您还可以手动运行段Advisor,以获得更多最新的建议,或者获得自动段Advisor没有检查的关于可能的空间回收的段的建议。

    See Also:

    "Using the Segment Advisor" for more information.
  • 自动SQL调优顾问—检查高负载SQL语句的性能,并就如何调优这些语句提出建议。您可以配置此advisor来自动实现SQL配置文件建议。

    See Also:

    Oracle Database Performance Tuning Guide for more information on SQL Tuning Advisor

By default, all three automated maintenance tasks are configured to run in all maintenance windows.

About Maintenance Windows

维护窗口是运行自动维护任务的连续时间间隔。维护窗口是属于窗口组MAINTENANCE_WINDOW_GROUP的Oracle调度程序窗口。调度程序窗口可以是一个简单的重复间隔(例如“午夜到凌晨6点之间”)。,或更复杂的时间段(如“午夜至凌晨6点之间”)。,每月最后一个工作日(不包括公司假期)。

当维护窗口打开时,Oracle Database为计划在该窗口中运行的每个维护任务创建一个Oracle调度程序作业。每个作业都分配了一个在运行时生成的作业名称。所有自动维护任务作业名称都以ORA$AT开头。例如,自动段顾问的工作可以称为ORA$AT_SA_SPC_SY_26。当自动维护任务作业完成时,它将从Oracle调度程序作业系统中删除。然而,作业仍然可以在调度程序作业历史记录中找到。

Note:

要查看作业历史记录,必须以SYS用户的身份登录。
在非常长的维护窗口的情况下,除了自动SQL调优Advisor外,所有自动维护任务每4小时重新启动一次。该特性确保定期运行维护任务,而不管窗口大小。
自动维护任务的框架依赖于数据库中定义的维护窗口。表26-1列出了每次新的Oracle数据库安装时自动定义的维护窗口。

See Also:

Configuring Automated Maintenance Tasks

要在维护窗口的任何子集中启用或禁用特定的维护任务,可以使用DBMS_AUTO_TASK_ADMINPL/SQL包。

This section contains the following topics:

Enabling and Disabling Maintenance Tasks for all Maintenance Windows

您可以通过一个操作禁用所有维护窗口的特定自动维护任务。为此,可以调用DBMS_AUTO_TASK_ADMIN PL/SQL包的DISABLE过程,而不提供window_name参数。例如,您可以完全禁用SQL自动调优Advisor任务,如下所示:

BEGIN
  dbms_auto_task_admin.disable(
    client_name => 'sql tuning advisor',
    operation   => NULL,
    window_name => NULL);
END;
/

To enable this maintenance task again, use the ENABLE procedure, as follows:

BEGIN
  dbms_auto_task_admin.enable(
    client_name => 'sql tuning advisor',
    operation   => NULL,
    window_name => NULL);
END;
/

The task names to use for the client_name argument are listed in the DBA_AUTOTASK_CLIENT database dictionary view.

To enable or disable all automated maintenance tasks for all windows, call the ENABLE or DISABLE procedure with no arguments.

EXECUTE DBMS_AUTO_TASK_ADMIN.DISABLE;

See Also:

Enabling and Disabling Maintenance Tasks for Specific Maintenance Windows

默认情况下,所有维护任务都在所有预定义的维护窗口中运行。您可以禁用特定窗口的维护任务。下面的示例禁止自动SQL调优顾问在窗口MONDAY_WINDOW中运行:

BEGIN
  dbms_auto_task_admin.disable(
    client_name => 'sql tuning advisor', 
    operation   => NULL, 
    window_name => 'MONDAY_WINDOW');
END;
/

Configuring Maintenance Windows

您可能希望将预定义的维护窗口调整到适合您的数据库环境的时间,或者创建一个新的维护窗口。您可以使用DBMS_SCHEDULER PL/SQL包自定义维护窗口。

This section contains the following topics:

Modifying a Maintenance Window

DBMS_SCHEDULER PL/SQL包包含一个用于修改窗口属性的SET_ATTRIBUTE过程。例如,下面的脚本将维护窗口SATURDAY_WINDOW的持续时间更改为4小时:

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;
/

注意,必须使用DBMS_SCHEDULER。禁用子程序以在更改窗口之前禁用该窗口,然后使用DBMS_SCHEDULER重新启用该窗口。完成后启用。如果您在窗口当前打开时更改它,则更改要到下次窗口打开时才生效。

See Also:

"Managing Job Scheduling and Job Priorities with Windows" for more information about modifying windows.

Creating a New Maintenance Window

要创建一个新的维护窗口,您必须创建一个Oracle调度程序窗口对象,然后将其添加到窗口组MAINTENANCE_WINDOW_GROUP中。使用DBMS_SCHEDULER。创建窗口的CREATE_WINDOW包过程,以及DBMS_SCHEDULER。将新窗口添加到窗口组的ADD_GROUP_MEMBER过程。

下面的示例创建一个名为EARLY_MORNING_WINDOW的维护窗口。这扇窗户每天早上5点到6点运行一小时。

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_group_member(
    group_name  => 'MAINTENANCE_WINDOW_GROUP',
    member      => 'EARLY_MORNING_WINDOW');
END;
/

See Also:

Removing a Maintenance Window

To remove an existing maintenance window, remove it from the MAINTENANCE_WINDOW_GROUP window group. The window continues to exist but no longer runs automated maintenance tasks. Any other Oracle Scheduler jobs assigned to this window continue to run as usual.

The following example removes EARLY_MORNING_WINDOW from the window group:

BEGIN
  DBMS_SCHEDULER.REMOVE_GROUP_MEMBER(
    group_name  => 'MAINTENANCE_WINDOW_GROUP',
    member      => 'EARLY_MORNING_WINDOW');
END;
/

See Also:

Configuring Resource Allocations for Automated Maintenance Tasks

This section contains the following topics on resource allocation for maintenance windows:

See Also:

Chapter 27, "Managing Resources with Oracle Database Resource Manager"

About Resource Allocations for Automated Maintenance Tasks

默认情况下,所有预定义的维护窗口都使用资源计划DEFAULT_MAINTENANCE_PLAN。自动维护任务在它的子计划或$AUTOTASK_SUB_PLAN下运行。该子计划将其在总资源分配中的部分平均分配给维护任务。

DEFAULT_MAINTENANCE_PLAN defines the following resource allocations:

Consumer 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% -  

在这个计划中,SYS_GROUP使用者组中的任何会话都获得优先级。(该组中的会话是由用户帐户SYS和SYSTEM创建的会话。)然后,SYS_GROUP中会话未使用的任何资源分配都由计划中属于其他使用者组和子计划的会话共享。其中25%用于维护任务,5%用于执行诊断操作的后台进程,70%用于用户会话。ORA$AUTOTASK_SUB_PLAN和ORA$DIAGNOSTICS的最大利用率限制为90。因此,即使CPU空闲,这个组/计划也不能空闲

要减少或增加对自动维护任务的资源分配,可以对DEFAULT_MAINTENANCE_PLAN进行调整。有关更多信息,请参见“更改自动维护任务的资源分配”。

请注意,与任何资源计划一样,分配中不被使用者组或子计划使用的部分可用于其他使用者组或子计划。还要注意,数据库资源管理器直到使用了100%的CPU后才开始根据资源计划限制资源分配。

Note:

虽然默认值是DEFAULT_MAINTENANCE_PLAN,但是您可以将任何资源计划分配给任何维护窗口。如果确实更改了维护窗口资源计划,请确保在新计划中包含子计划或$AUTOTASK_SUB_PLAN以及消费组或$DIAGNOSTICS

See Also:

Chapter 27, "Managing Resources with Oracle Database Resource Manager" for more information on resource plans.

Changing Resource Allocations for Automated Maintenance Tasks

要更改维护窗口内自动维护任务的资源分配,您必须更改该窗口的资源计划中分配给子计划或$AUTOTASK_SUB_PLAN的资源百分比。(默认情况下,每个预定义维护窗口的资源计划是DEFAULT_MAINTENANCE_PLAN。)您还必须调整窗口资源计划中的一个或多个其他子计划或消费者组的资源分配,使计划顶层的资源分配之和达到100%。有关更改资源分配的信息,请参阅 Chapter 27, "Managing Resources with Oracle Database Resource Manager".

Automated Maintenance Tasks Reference

This section contains the following reference topics for automated maintenance tasks:

Predefined Maintenance Windows

默认情况下,有七个预定义的维护窗口,每个窗口表示一周中的一天。周末维护窗口(星期六窗口和星期日窗口)的持续时间比工作日维护窗口长。窗口组MAINTENANCE_WINDOW_GROUP由这七个窗口组成. The list of predefined maintenance windows is given in Table 26-1.

Table 26-1 Predefined Maintenance Windows

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.


Automated Maintenance Tasks Database Dictionary Views

Table 26-2 displays information about database dictionary views for automated maintenance tasks:

Table 26-2 Automated Maintenance Tasks Database Dictionary Views

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.

See Also:

"Resource Manager Data Dictionary Views" for column descriptions for views.

猜你喜欢

转载自blog.csdn.net/viviliving/article/details/88885712