【11g】工作优先级Prioritizing Jobs

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

Prioritizing Jobs

使用三个调度器对象对Oracle调度器作业进行优先级排序:作业类、窗口和窗口组。这些对象通过将作业与数据库资源管理器使用者组关联来对作业进行优先级排序。这反过来控制分配给这些作业的资源数量。此外,如果组中的所有作业都分配了相同的资源级别,作业类使您能够在一组作业之间设置相对的优先级。

This section contains:

See Also:

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

扫描二维码关注公众号,回复: 6423027 查看本文章

Managing Job Priorities with Job Classes

作业类提供了对作业进行分组以确定优先级的方法。它们还提供了一种方法,可以方便地为成员作业分配一组属性值。作业类通过与数据库资源管理器相关的作业类属性影响其成员作业的优先级。有关详细信息,请参阅“使用资源管理器在作业之间分配资源”。

有一个使用数据库创建的默认作业类。如果您创建一个作业而没有指定作业类,那么该作业将被分配给这个默认作业类(DEFAULT_JOB_CLASS)。默认作业类具有授予PUBLIC的执行特权,因此任何具有创建作业特权的数据库用户都可以在默认作业类中创建作业。

This section introduces you to basic job class tasks, and discusses the following topics:

See Also:

"Job Classes" for an overview of job classes.

Job Class Tasks and Their Procedures

Table 29-8 illustrates common job class tasks and their appropriate procedures and privileges:

Table 29-8 Job Class Tasks and Their Procedures

Task Procedure Privilege Needed

Create a job class

CREATE_JOB_CLASS

MANAGE SCHEDULER

Alter a job class

SET_ATTRIBUTE

MANAGE SCHEDULER

Drop a job class

DROP_JOB_CLASS

MANAGE SCHEDULER

See "Scheduler Privileges" for further information regarding privileges.

Creating Job Classes

You create a job class using the CREATE_JOB_CLASS procedure or Enterprise Manager. Job classes are always created in the SYS schema.

The following statement creates a job class for all finance jobs:

BEGIN
  DBMS_SCHEDULER.CREATE_JOB_CLASS (
   job_class_name             =>  'finance_jobs', 
   resource_consumer_group    =>  'finance_group');
END;
/

All jobs in this job class are assigned to the finance_group resource consumer group.

To query job classes, use the *_SCHEDULER_JOB_CLASSES views.

See Also:

"About Resource Consumer Groups"

Altering Job Classes

You alter a job class by using the SET_ATTRIBUTE procedure or Enterprise Manager. Other than the job class name, all the attributes of a job class can be altered. The attributes of a job class are available in the *_SCHEDULER_JOB_CLASSES views.

When a job class is altered, running jobs that belong to the class are not affected. The change only takes effect for jobs that have not started running yet.

Dropping Job Classes

You drop one or more job classes using the DROP_JOB_CLASS procedure or Enterprise Manager. Dropping a job class means that all the metadata about the job class is removed from the database.

You can drop several job classes in one call by providing a comma-delimited list of job class names to the DROP_JOB_CLASS procedure call. For example, the following statement drops three job classes:

BEGIN
  DBMS_SCHEDULER.DROP_JOB_CLASS('jobclass1, jobclass2, jobclass3');
END;
/

Setting Relative Job Priorities Within a Job Class

You can change the relative priorities of jobs within the same job class by using the SET_ATTRIBUTE procedure. Job priorities must be in the range of 1-5, where 1 is the highest priority. For example, the following statement changes the job priority for my_job1 to a setting of 1:

BEGIN
  DBMS_SCHEDULER.SET_ATTRIBUTE (
   name           =>   'my_emp_job1',
   attribute      =>   'job_priority',
   value          =>   1);
END;
/

You can verify that the attribute was changed by issuing the following statement:

SELECT JOB_NAME, JOB_PRIORITY FROM DBA_SCHEDULER_JOBS;

JOB_NAME                       JOB_PRIORITY
------------------------------ ------------
MY_EMP_JOB                                3
MY_EMP_JOB1                               1
MY_NEW_JOB1                               3
MY_NEW_JOB2                               3
MY_NEW_JOB3                               3

Overall priority of a job within the system is determined first by the combination of the resource consumer group that the job's job class is assigned to and the current resource plan, and then by relative priority within the job class.

See Also:

Managing Job Scheduling and Job Priorities with Windows

Windows提供了在不同时间自动激活不同资源计划的方法。然后,当资源计划发生更改时,运行作业可以看到分配给它们的资源中的更改。作业可以在其schedule_name属性中为窗口命名。然后,调度程序以“打开”窗口启动作业。一个窗口有一个与之关联的时间表,因此一个窗口可以在工作负载周期的不同时间打开。

The key attributes of a window are its:

  • Schedule

    This controls when the window is in effect.

  • Duration

    This controls how long the window is open.

  • Resource plan

    This names the resource plan that activates when the window opens.

Only one window can be in effect at any given time. Windows belong to the SYS schema.

All window activity is logged in the *_SCHEDULER_WINDOW_LOG views, otherwise known as the window logs. See "Window Log" for examples of window logging.

This section introduces you to basic window tasks, and discusses the following topics:

See Also:

"Windows" for an overview of windows.

Window Tasks and Their Procedures

Table 29-9 illustrates common window tasks and the procedures you use to handle them.

Table 29-9 Window Tasks and Their Procedures

Task Procedure Privilege Needed

Create a window

CREATE_WINDOW

MANAGE SCHEDULER

Open a window

OPEN_WINDOW

MANAGE SCHEDULER

Close a window

CLOSE_WINDOW

MANAGE SCHEDULER

Alter a window

SET_ATTRIBUTE

MANAGE SCHEDULER

Drop a window

DROP_WINDOW

MANAGE SCHEDULER

Disable a window

DISABLE

MANAGE SCHEDULER

Enable a window

ENABLE

MANAGE SCHEDULER

See "Scheduler Privileges" for further information regarding privileges.

Creating Windows

You can use Enterprise Manager or the DBMS_SCHEDULER.CREATE_WINDOW package procedure to create windows. When using the package procedure, you can leave the resource_plan parameter NULL. In this case, when the window opens, the current plan remains in effect.

You must have the MANAGE SCHEDULER privilege to create windows.

When you specify a schedule for a window, the Scheduler does not check if there is already a window defined for that schedule. Therefore, this may result in windows that overlap. Also, using a named schedule that has a PL/SQL expression as its repeat interval is not supported for windows

See the CREATE_WINDOW procedure in Oracle Database PL/SQL Packages and Types Reference for details on window attributes.

The following example creates a window named daytime that enables the mixed_workload_plan resource plan during office hours:

BEGIN
   DBMS_SCHEDULER.CREATE_WINDOW (
     window_name      => 'daytime',
     resource_plan    => 'mixed_workload_plan',
     start_date       => '28-APR-09 08.00.00 AM',
     repeat_interval  => 'freq=daily; byday=mon,tue,wed,thu,fri',
     duration         => interval '9' hour,
     window_priority  => 'low',
     comments         => 'OLTP transactions have priority');
END;
/

To verify that the window was created properly, query the view DBA_SCHEDULER_WINDOWS. As an example, issue the following statement:

SELECT WINDOW_NAME, RESOURCE_PLAN, DURATION, REPEAT_INTERVAL FROM DBA_SCHEDULER_WINDOWS;

WINDOW_NAME   RESOURCE_PLAN         DURATION       REPEAT_INTERVAL
-----------   -------------------   -------------  ---------------
DAYTIME       MIXED_WORKLOAD_PLAN   +000 09:00:00  freq=daily; byday=mon,tue,wed,thu,fri

Altering Windows

You alter a window by modifying its attributes. You do so with the SET_ATTRIBUTE and SET_ATTRIBUTE_NULL procedures or Enterprise Manager. With the exception of WINDOW_NAME, all the attributes of a window can be changed when it is altered. See the CREATE_WINDOWprocedure in Oracle Database PL/SQL Packages and Types Reference for window attribute details.

When a window is altered, it does not affect an active window. The changes only take effect the next time the window opens.

All windows can be altered. If you alter a window that is disabled, it will remain disabled after it is altered. An enabled window will be automatically disabled, altered, and then reenabled, if the validity checks performed during the enable process are successful.

See Oracle Database PL/SQL Packages and Types Reference for detailed information about the SET_ATTRIBUTE and SET_ATTRIBUTE_NULLprocedures.

Opening Windows

When a window opens, the Scheduler switches to the resource plan that has been associated with it during its creation. If there are jobs running when the window opens, the resources allocated to them might change due to the switch in resource plan.

There are two ways a window can open:

  • According to the window's schedule

  • Manually, using the OPEN_WINDOW procedure

    This procedure opens the window independent of its schedule. This window will open and the resource plan associated with it will take effect immediately. Only an enabled window can be manually opened.

    In the OPEN_WINDOW procedure, you can specify the time interval that the window should be open for, using the duration attribute. The duration is of type interval day to second. If the duration is not specified, then the window will be opened for the regular duration as stored with the window.

    Opening a window manually has no impact on regular scheduled runs of the window.

    When a window that was manually opened closes, the rules about overlapping windows are applied to determine which other window should be opened at that time if any at all.

    You can force a window to open even if there is one already open by setting the force option to TRUE in the OPEN_WINDOW call or Enterprise Manager.

    When the force option is set to TRUE, the Scheduler automatically closes any window that is open at that time, even if it has a higher priority. For the duration of this manually opened window, the Scheduler does not open any other scheduled windows even if they have a higher priority. You can open a window that is already open. In this case, the window stays open for the duration specified in the call, from the time the OPEN_WINDOW command was issued.

    Consider an example to illustrate this. window1 was created with a duration of four hours. It has how been open for two hours. If at this point you reopen window1 using the OPEN_WINDOW call and do not specify a duration, then window1 will be open for another four hours because it was created with that duration. If you specified a duration of 30 minutes, the window will close in 30 minutes.

When a window opens, an entry is made in the window log.

A window can fail to switch resource plans if the current resource plan has been manually switched using the ALTER SYSTEM statement with the FORCE option, or using the DBMS_RESOURCE_MANAGER.SWITCH_PLAN package procedure with the allow_scheduler_plan_switchesargument set to FALSE. In this case, the failure to switch resource plans is written to the window log.

See Oracle Database PL/SQL Packages and Types Reference for detailed information about the OPEN_WINDOW procedure and the DBMS_RESOURCE_MANAGER.SWITCH_PLAN procedure.

Closing Windows

There are two ways a window can close:

  • Based on a schedule

    A window will close based on the schedule defined at creation time.

  • Manually, using the CLOSE_WINDOW procedure

    The CLOSE_WINDOW procedure will close an open window prematurely.

A closed window means that it is no longer in effect. When a window is closed, the Scheduler will switch the resource plan to the one that was in effect outside the window or in the case of overlapping windows to another window. If you try to close a window that does not exist or is not open, an error is generated.

A job that is running will not close when the window it is running in closes unless the attribute stop_on_window_close was set to TRUE when the job was created. However, the resources allocated to the job may change because the resource plan may change.

When a running job has a window group as its schedule, the job will not be stopped when its window is closed if another window that is also a member of the same window group then becomes active. This is the case even if the job was created with the attribute stop_on_window_close set to TRUE.

When a window is closed, an entry will be added to the window log DBA_SCHEDULER_WINDOW_LOG.

See Oracle Database PL/SQL Packages and Types Reference for detailed information about the CLOSE_WINDOW procedure.

Dropping Windows

You drop one or more windows using the DROP_WINDOW procedure or Enterprise Manager. When a window is dropped, all metadata about the window is removed from the *_SCHEDULER_WINDOWS views. All references to the window are removed from window groups.

You can drop several windows in one call by providing a comma-delimited list of window names or window group names to the DROP_WINDOWprocedure. For example, the following statement drops both windows and window groups:

BEGIN
  DBMS_SCHEDULER.DROP_WINDOW ('window1, window2, window3, 
   windowgroup1, windowgroup2');
END;
/

Note that if a window group name is provided, then the windows in the window group are dropped, but the window group is not dropped. To drop the window group, you must use the DROP_WINDOW_GROUP procedure.

See Oracle Database PL/SQL Packages and Types Reference for detailed information about the DROP_WINDOW procedure.

Disabling Windows

You disable one or more windows using the DISABLE procedure or with Enterprise Manager. Therefore, the window will not open. However, the metadata of the window is still there, so it can be reenabled. Because the DISABLE procedure is used for several Scheduler objects, when disabling windows, they must be preceded by SYS.

A window can also become disabled for other reasons. For example, a window will become disabled when it is at the end of its schedule. Also, if a window points to a schedule that no longer exists, it becomes disabled.

If there are jobs that have the window as their schedule, you will not be able to disable the window unless you set force to TRUE in the procedure call. By default, force is set to FALSE. When the window is disabled, those jobs that have the window as their schedule will not be disabled.

You can disable several windows in one call by providing a comma-delimited list of window names or window group names to the DISABLEprocedure call. For example, the following statement disables both windows and window groups:

BEGIN
  DBMS_SCHEDULER.DISABLE ('sys.window1, sys.window2, 
   sys.window3, sys.windowgroup1, sys.windowgroup2');
END;
/

See Oracle Database PL/SQL Packages and Types Reference for detailed information about the DISABLE procedure.

Enabling Windows

You enable one or more windows using the ENABLE procedure or Enterprise Manager. An enabled window is one that can be opened. Windows are, by default, created enabled. When a window is enabled using the ENABLE procedure, a validity check is performed and only if this is successful will the window be enabled. When a window is enabled, it is logged in the window log table. Because the ENABLE procedure is used for several Scheduler objects, when enabling windows, they must be preceded by SYS.

You can enable several windows in one call by providing a comma-delimited list of window names. For example, the following statement enables three windows:

BEGIN
  DBMS_SCHEDULER.ENABLE ('sys.window1, sys.window2, sys.window3');
END;
/

See Oracle Database PL/SQL Packages and Types Reference for detailed information about the ENABLE procedure.

Managing Job Scheduling and Job Priorities with Window Groups

窗口组提供了一种简单的方法来安排必须在一天、一周等多个时间段内运行的作业。如果创建一个窗口组,将窗口添加到其中,然后在作业的schedule_name属性中命名该窗口组,则该作业将在窗口组中的所有窗口期间运行

Window groups reside in the SYS schema. This section introduces you to basic window group tasks, and discusses the following topics:

See Also:

"Window Groups" for an overview of window groups.

Window Group Tasks and Their Procedures

Table 29-10 illustrates common window group tasks and the procedures you use to handle them.

Table 29-10 Window Group Tasks and Their Procedures

Task Procedure Privilege Needed

Create a window group

CREATE_GROUP

MANAGE SCHEDULER

Drop a window group

DROP_GROUP

MANAGE SCHEDULER

Add a member to a window group

ADD_GROUP_MEMBER

MANAGE SCHEDULER

Drop a member from a window group

REMOVE_GROUP_MEMBER

MANAGE SCHEDULER

Enable a window group

ENABLE

MANAGE SCHEDULER

Disable a window group

DISABLE

MANAGE SCHEDULER

See "Scheduler Privileges" for further information regarding privileges.

Creating Window Groups

使用DBMS_SCHEDULER创建窗口组。CREATE_GROUP过程,指定“窗口”的组类型。您可以在创建组时指定组的成员窗口,或者稍后使用ADD_GROUP_MEMBER过程添加它们。窗口组不能是另一个窗口组的成员。但是,您可以创建一个没有成员的窗口组。

如果您创建一个窗口组并指定一个不存在的成员窗口,则会生成一个错误,并且不会创建窗口组。如果窗口已经是窗口组的成员,则不再添加它。
窗口组是在SYS模式中创建的。与windows一样,创建窗口组时具有访问PUBLIC的权限,因此,访问窗口组不需要特权。

The following statement creates a window group called downtime and adds two windows (weeknights and weekends) to it:

BEGIN
  DBMS_SCHEDULER.CREATE_GROUP (
   group_name   =>  'downtime',
   group_type   =>  'WINDOW',
   member       =>  'weeknights, weekends');
END;
/

To verify the window group contents, issue the following queries as a user with the MANAGE SCHEDULER privilege:

SELECT group_name, enabled, number_of_members FROM dba_scheduler_groups
  WHERE group_type = 'WINDOW';

GROUP_NAME     ENABLED  NUMBER_OF_MEMBERS
-------------- -------- -----------------
DOWNTIME       TRUE                     2

SELECT group_name, member_name FROM dba_scheduler_group_members;

GROUP_NAME      MEMBER_NAME
--------------- --------------------
DOWNTIME        "SYS"."WEEKENDS"
DOWNTIME        "SYS"."WEEKNIGHTS"

Dropping Window Groups

You drop one or more window groups by using the DROP_GROUP procedure. This call will drop the window group but not the windows that are members of this window group. To drop all the windows that are members of this group but not the window group itself, you can use the DROP_WINDOW procedure and provide the name of the window group to the call.

You can drop several window groups in one call by providing a comma-delimited list of window group names to the DROP_GROUP procedure call. You must precede each window group name with the SYS schema. For example, the following statement drops three window groups:

BEGIN
DBMS_SCHEDULER.DROP_GROUP('sys.windowgroup1, sys.windowgroup2, sys.windowgroup3');
END;
/

Adding a Member to a Window Group

You add windows to a window group by using the ADD_GROUP_MEMBER procedure.

You can add several members to a window group in one call, by specifying a comma-delimited list of windows. For example, the following statement adds two windows to the window group window_group1:

BEGIN
  DBMS_SCHEDULER.ADD_GROUP_MEMBER ('sys.windowgroup1','window2, window3');
END;
/

If an already open window is added to a window group, the Scheduler will not start jobs that point to this window group until the next window in the window group opens.

Removing a Member from a Window Group

You can remove one or more windows from a window group by using the REMOVE_GROUP_MEMBER procedure. Jobs with the stop_on_window_close flag set will only be stopped when a window closes. Dropping an open window from a window group has no impact on this.

You can remove several members from a window group in one call by specifying a comma-delimited list of windows. For example, the following statement drops two windows:

BEGIN
  DBMS_SCHEDULER.REMOVE_GROUP_MEMBER('sys.window_group1', 'window2, window3');
END;
/

Enabling a Window Group

You enable one or more window groups using the ENABLE procedure. By default, window groups are created ENABLED. For example:

BEGIN
  DBMS_SCHEDULER.ENABLE('sys.windowgroup1, sys.windowgroup2, sys.windowgroup3');
END;
/

Disabling a Window Group

You disable a window group using the DISABLE procedure. A job with a disabled window group as its schedule does not run when the member windows open. Disabling a window group does not disable its member windows.

You can also disable several window groups in one call by providing a comma-delimited list of window group names. For example, the following statement disables three window groups:

BEGIN
  DBMS_SCHEDULER.DISABLE('sys.windowgroup1, sys.windowgroup2, sys.windowgroup3');
END;
/

使用资源管理器在作业之间分配资源

数据库资源管理器(资源管理器)控制如何在数据库会话之间分配资源。它不仅控制诸如调度程序作业之类的异步会话,还控制诸如用户会话之类的同步会话。它将数据库中的所有“工作单元”分组到资源使用者组中,并使用资源计划来指定如何在各个使用者组之间分配资源。资源管理器分配的主要系统资源是CPU。

对于调度程序作业,首先将每个作业分配给作业类,然后将作业类与使用者组关联,从而分配资源。然后,资源被分配到调度程序作业和使用者组中的其他会话中。您还可以为作业类中的作业分配相对的优先级,并相应地将资源分配给这些作业。

您可以随时手动更改当前资源计划。更改当前资源计划的另一种方法是创建调度程序窗口。Windows有一个资源计划属性。当窗口打开时,当前计划将切换到窗口的资源计划。

调度程序试图限制同时运行的作业的数量,以便至少有一些作业可以完成,而不是同时运行许多作业,但是没有足够的资源来完成它们。

调度程序和资源管理器是紧密集成的。作业协调器从资源管理器获得数据库资源可用性。根据这些信息,协调器确定要启动多少个作业。它只会从那些有足够资源运行的作业类启动作业。协调器将继续启动映射到使用者组的特定作业类中的作业,直到资源管理器确定已达到为该使用者组分配的最大资源为止。因此,作业表中可能有一些作业已经准备好运行,但是作业协调器不会接收它们,因为没有资源来运行它们。因此,不能保证作业将在计划的确切时间运行。协调器从job表中获取作业,根据这些作业,消费者组仍然拥有可用的资源。

资源管理器继续管理根据指定的资源计划分配给每个正在运行的作业的资源。请记住,资源管理器只能管理数据库进程。资源的主动管理不适用于外部工作。

Note:

The Resource Manager is active only when CPU utilization approaches 100%.

See Also:

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

作业的资源分配示例

下面的示例演示了如何为作业分配资源。假设活动资源计划称为“夜间计划”,并且有三个作业类:JC1,它映射到消费者组DW;映射到消费者组OLTP的JC2;以及映射到默认消费者组的JC3。图29-2提供了此场景的简单图形说明。

Figure 29-2 Sample Resource Plan

Description of Figure 29-2 follows
Description of "Figure 29-2 Sample Resource Plan"
 

这个资源计划显然优先考虑属于作业类JC1的作业。消费者组DW获得60%的资源,因此属于作业类JC1的作业将获得60%的资源。消费者组OLTP拥有30%的资源,这意味着作业类jc2中的作业将获得30%的资源。消费者组Other指定所有其他消费者组将获得10%的资源。因此,属于作业类JC3的所有作业将共享10%的资源,并且最多可以获得10%的资源。

请注意,一个消费者组仍然未使用的资源可以由其他消费者组使用。因此,如果作业类JC1中的作业没有完全使用分配的60%,则JC2和JC3中的作业可以使用未使用的部分。还要注意,直到CPU使用率达到100%,资源管理器才开始限制资源的使用。See Chapter 27, "Managing Resources with Oracle Database Resource Manager" for more information.

猜你喜欢

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