Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Oracle Database 11g.pdf
Скачиваний:
77
Добавлен:
10.06.2015
Размер:
12.69 Mб
Скачать

602

Chapter 12  n  Using the Scheduler to Automate Tasks

3

‘LOG_HISTORY’,’60’);

4

end;

SQL>

/

PL/SQL procedure successfully completed.

This example instructs Oracle to automatically purge all records that are over 60 days old.

By default, this procedure sets the history retention period for both Scheduler window logs and Scheduler job logs. To set only one, you may include the WHICH_LOG parameter to specify either WINDOW_LOG or JOB_LOG.

Creating and Using Job Classes

A job class is a container object for the logical grouping of jobs into a larger unit. Classifying jobs in this manner offers several advantages:

NNFrom an administrative perspective, it is easier to manage a small number of job groups than to manage a large number of individual jobs. Certain job characteristics can be assigned at the group level and will be inherited by all jobs within the group. Certain administrative procedures will also operate at the group level, making administrative functions easier.

NNJob classes can be assigned to a resource consumer group. This allows you to control resource allocation for all jobs within the group.

NNJobs can be prioritized within the job class. This gives you more control over which jobs should take precedence in case of a conflict. For example, if a conflict occurs, the JOB_ PRIORITY attribute of each job will be evaluated. A job with a value of HIGH takes priority over a job with a value of LOW.

All jobs must belong to exactly one job class. Any job not explicitly assigned to a job class will belong to the DEFAULT_JOB_CLASS class and will inherit the characteristics of that job class. In the following sections, you will learn to create and administer job classes.

Job Class Parameters

Job classes have a specific set of attributes that you can set to define the characteristics of the class. These attributes will be inherited by all jobs assigned to the job class, thereby saving you the work of setting them individually on each job. The available attribute parameters are described here:

JOB_CLASS_NAME  The JOB_CLASS_NAME parameter uniquely identifies the job class in the SYS schema. The name has to be unique in the SYS schema.

Creating and Using Job Classes 

603

RESOURCE_CONSUMER_GROUP  The RESOURCE_CONSUMER_GROUP parameter associates the job group with a specific consumer group. All jobs assigned to the job group will automatically be governed by this consumer group.

SERVICE  The SERVICE parameter specifies the service to which the job class belongs. This means that, in a RAC environment, the jobs in this class will have affinity to the particular service specified. Therefore, they will run only on those database instances that are assigned to the specific service. If this attribute is not set, the default service will be used, meaning that the jobs have no service affinity and can be run by any instance within the cluster. If the SERVICE parameter is specified, the RESOURCE_CONSUMER_GROUP attribute cannot be set. They are mutually exclusive.

LOGGING_LEVEL  The Oracle Scheduler can optionally maintain job logs of all job activities. Job logging is determined by the setting of the LOGGING_LEVEL attribute of the job class. The LOGGING_LEVEL parameter specifies how much job information is logged. There are four valid settings for this attribute:

DBMS_SCHEDULER.LOGGING_OFF  No logging will be performed for any jobs in this class.

DBMS_SCHEDULER.LOGGING_RUNS  Detailed information will be written for all runs of each job in the class.

DBMS_SCHEDULER.LOGGING_FULL  Detailed information will be written for all runs of each job in the class, and every operation performed on any job in the class (create, enable, drop, and so on) will be logged.

DBMS_SCHEDULER.LOGGING_FAILED_RUNS  Logs only jobs that failed and the reason for failure. If the job class has a higher logging level the higher level takes precedence.

Note that the valid values for this parameter are all constants defined within the DBMS_ SCHEDULER package. Therefore, they must be referenced exactly as shown, with no quotes around them.

LOG_HISTORY  The LOG_HISTORY parameter determines the number of days logged information should be retained. The default value is 30 days. Valid values are 1 to 999. When records have exceeded this limit, the Scheduler will automatically purge them.

COMMENTS  The COMMENTS parameter specifies an optional comment about the job class.

Creating Job Classes

Job classes can be created through the DBMS_SCHEDULER.CREATE_JOB_CLASS procedure, as shown in the following example:

SQL> begin

2dbms_scheduler.create_job_class(

3 job_class_name => ‘LOW_PRIORITY_CLASS’, 4 resource_consumer_group => ‘LOW_GROUP’,

604  Chapter 12  n  Using the Scheduler to Automate Tasks

5 logging_level => DBMS_SCHEDULER.LOGGING_FULL,

6log_history => 60,

7 comments => ‘LOW PRIORITY JOB CLASS’);

8 end; SQL> /

PL/SQL procedure successfully completed.

In this example, a job class named LOW_PRIORITY_CLASS was created that will assign all jobs in the group to the LOW_GROUP consumer group.

Dropping Job Classes

Job classes can be dropped by using the DBMS_SCHEDULER.DROP_JOB_CLASS procedure. Dropping a job class that has jobs assigned to it will result in an error. However, it is allowed if the FORCE parameter is set to TRUE. In this case, the job class will be dropped and the jobs assigned to the class will be disabled. Dropping the class has no effect on any currently running instances of member jobs.

Several job classes can also be dropped at the same time by separating the names of the job classes by a comma, as shown in the following example:

SQL> begin

2dbms_scheduler.drop_job_class(

3 ‘LOW_PRIORITY_CLASS, HIGH_PRIORITY_CLASS’); 4 end;

SQL> /

PL/SQL procedure successfully completed.

Note that if a list of job classes is used, as in the example in the section “Dropping Job Classes,” there is no rollback available. For instance, if the first job class dropped but the second job class failed to drop, the procedure will return an error, but the first job class will not be restored.

Using Advanced Scheduler Concepts to Prioritize Jobs

The Scheduler allows you to prioritize jobs based on your unique business requirements. It gives you control over resource allocation through job classes, as described earlier. It also allows you to change the prioritization based on a schedule.

Using Scheduler Views 

605

When working with a job class, you can define a resource consumer group and take advantage of the Database Resource Manager capabilities, as described earlier in this chapter. You can also prioritize jobs within a job class.

Prioritizing Jobs within a Job Class

Within a job class, you can assign priority values from 1 to 5 to individual jobs so that if more than one job within the same class starts at the same time, the job with the highest priority will take precedence over the others. If two jobs have the same priority, the one that had the earlier start date gets the higher priority. Priority rules apply only when comparing jobs within the same class. The default priority for a job is 3; 1 is the highest, and 5 is the lowest.

To change a job priority, use the SET_ATTRIBUTE procedure. For example, here’s how to raise the priority of the LNE_JOB1 job to priority 1:

BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE (

name => ‘lne_job1’, attribute => ‘job_priority’, value => 1);

END;

/

The job_priority attribute is set by default to 3 when you create the job; use the SET_ATTRIBUTE procedure to change the job priority.

Using Scheduler Views

Oracle offers a wide variety of views to access information regarding the Scheduler and its associated objects. These views allow you to see information about currently running jobs and past runs of jobs. Table 12.5 describes the available Scheduler views.

Ta b l e 12 . 5   ​  Scheduler​ Views Available

View

Description

 

 

*_SCHEDULER_SCHEDULES

Shows information on all defined schedules.

*_SCHEDULER_PROGRAMS

Shows information on all defined programs.

606  Chapter 12  n  Using the Scheduler to Automate Tasks

Ta b l e 12 . 5   ​  Scheduler​ Views Available  (continued)

View

Description

*_SCHEDULER_PROGRAM_ARGUMENTS

*_SCHEDULER_JOBS *_SCHEDULER_GLOBAL_ATTRIBUTE *_SCHEDULER_JOB_ARGUMENTS *_SCHEDULER_JOB_CLASSES *_SCHEDULER_WINDOWS *_SCHEDULER_JOB_RUN_DETAILS

*_SCHEDULER_WINDOW_GROUPS *_SCHEDULER_WINGROUP_MEMBERS *_SCHEDULER_RUNNING_JOBS

Shows all registered program arguments and the default values if they exist.

Shows all defined jobs, both enabled and disabled. Shows the current values of all Scheduler attributes. Shows the arguments for all defined jobs.

Shows information on all defined job classes. Shows information about all defined windows.

Shows information about all completed (failed or successful) job runs.

Shows information about all window groups. Shows the members of all window groups.

Shows the state information on all jobs that are currently being run.

To see information on completed instances of a job, use the code shown here:

SQL> select job_name, status, error#

2 from dba_scheduler_job_run_details

3where job_name = ‘FAIL_JOB’;

JOB_NAME

STATUS

ERROR#

--------

--------------

------

FAIL_JOB

FAILURE

20000

To see the current state of all jobs, use the following code:

SQL> select job_name, state

2from dba_scheduler_jobs;

JOB_NAME

STATE

-----------------

---------------

PURGE_LOG

SCHEDULED

GATHER_STATS_JOB

SCHEDULED

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]