Presentation is loading. Please wait.

Presentation is loading. Please wait.

SCHEDULING IN ORACLE DATABASE 10G

Similar presentations


Presentation on theme: "SCHEDULING IN ORACLE DATABASE 10G"— Presentation transcript:

1

2 SCHEDULING IN ORACLE DATABASE 10G
40165 SCHEDULING IN ORACLE DATABASE 10G Vira Goorah Product Manager Oracle Corporation

3 What is a Job? What Schedule Job Attributes Job Arguments
A job is a combination of a schedule and a description of what to do, along with any additional arguments required by the program. The what can be a pre-created PL/SQL or Java program, an anonymous PL/SQL block, or an external program that is executed from the operating system’s command line. The schedule used by a job can either be a predefined schedule created with the DBMS_SCHDULER.CREATE_SCHEDULE procedure, or you can specify the schedule parameters as part of the job creation. The schedule specifies attributes about when the job is run, such as: A start time which defines when the job will be picked for execution An end time which specifies the time after which the job is no longer be valid and is not scheduled any more. An expression specifying a repeating interval for the job. There are many attributes that you can set for a job. They include: job_class job_priority auto_drop restartable max_runs max_failures schedule_limit max_run_duration logging_level This is a list of the more common job attributes. For a complete list of attributes, see the ALL_SCHEDULER_JOBS view. You can set job attributes when creating the job, or through the SET_ATTRIBUTE procedure of DBMS_SCHEDULER. Arguments

4 Scheduler Solution Program Schedule Job
To help you simplify your management tasks as well as providing a rich set of functionality for complex scheduling needs, Oracle provides a collection of functions and procedures in the DBMS_SCHEDULER package. Collectively, these functions are called the Scheduler, and they are callable from any PL/SQL program. The Scheduler enables database administrators and application developers to control when and where various tasks take place. These tasks can be time consuming and complicated, so using the Scheduler can help you to improve the management and planning of these tasks. In addition, by ensuring that many routine database tasks occur without manual intervention, you can lower operating costs, implement more reliable routines, and minimize human error. The Scheduler uses three main components: A schedule specifies when and how many times a job is executed. Similar to programs, schedules are database entities and can be saved in the database. The same schedule can be used by multiple jobs. A program is a collection of metadata about what will be run by the scheduler. This includes information such as the program name, the type of program, information about arguments passed to the program. A job specifies what needs to executed and when. For example, the "what" could be a PL/SQL procedure, an executable C program, a java application, a shell script, or client-side PL/SQL. You can specify the program (what) and schedule (when) as part of the job definition, or you can use an existing program or schedule instead.

5 Run CALC_STATS every two hours
Job Instance Run CALC_STATS every two hours Execute job at 10:00 am Execute job at 12:00 pm 8:00 am 10:00 am 12:00 pm 2:00 pm A job instance represents a specific execution of a scheduled job. While a scheduled job may be defined to run at repeated intervals, such as every two hours, a job instance represents a particular instance of the job. For example, in the graphic above, the job instance at 10:00 am is distinct from the job instance at 12:00 pm. A job instance is created from a scheduled job automatically. You do not create a job instance, but you can monitor and manage job instances. A job instance is useful for: Diagnosing individual runs Viewing job output

6 Specifying Schedules for a Job
Defines a time for: Starting a job Repeat interval or the next time the job executes Ending repeating job executions Example schedules: Wed, December 26th, 2002 at 2:00 pm Every Monday at 8:00 am, starting on January 29th, 2003 and ending on March 31st, 2003 Every fourth Thursday The start and end time for a schedule is specified using the TIMESTAMP data type. A schedule is only precise to a second. Although the TIMESTAMP data type is more accurate, the scheduler rounds off anything with a higher precision to the nearest second. The repeat_interval for a saved schedule must be created using a calendaring expression. You cannot use PL/SQL expressions to express the repeat interval for a saved schedule. The end_date for a saved schedule is the date after which the schedule is no longer valid. The Scheduler fully supports all NLS functionality provided by the database. For example, you can use all NLS_TIMESTAMP_FORMAT settings, as well as TIMESTAMP WITH TIME ZONE data types. As a result, the following time specifications are all valid: 1:00:00 pm 13:00:00 hrs :00:00 US/Pacific 8:00:00 -8: :26:50.124

7 Defining Repeat Intervals for a Schedule
One Time Job Start Time Schedule Repeating Job End Time or Limit Examples: Starting now, run the job every 2 hours Starting on April 2, 2003, run every 6 hours until midnight on April 15th, 2003. Run on the last Sunday of every other month at 8:00 pm A schedule can optionally have a repeat interval. Repeat intervals can be anything from seconds, minutes, hours, days, weeks, months to years. Some example intervals are: Every 5 seconds Every day at 12:00:00 am Every week on Monday, Wednesday, and Friday, at 9:00:00 pm Every month on the 2nd Friday at 3:00:00 am Every month on the 12th at 08:30 am If you have specified a repeat interval for your job execution, you can also specify the end time for this interval. At the specified end time the job will automatically be disabled. If no end time is specified, the job will continue to be repeated forever or until it is explicitly or implicitly disabled. You can specify repeat intervals and end times to the second. This means a scheduled interval of every second is valid. It also means that a job that is scheduled at 11:20:07 should not be executed at 11:20. The start date is when the schedule becomes valid. The time at which the job will execute for the first time depends on the repeat interval as well as the start date. For example, if the start date is at midnight, and the repeat interval is every day at 6:00 pm, the job will not start at midnight, but at 6:00 pm on the same day as the start date. The scheduler does not guarantee to actually start the job at its scheduled time. If the system load is very high and resources are scarce, jobs might be delayed in their execution.

8 Calendaring Expressions
BYMONTH BYWEEKNO BYYEARDAY BYMONTHDAY BYDAY BYHOUR BYMINUTE BYSECOND YEARLY MONTHLY WEEKLY DAILY HOURLY MINUTELY SECONDLY INTERVAL (1-99) The primary method of setting how often a job will repeat is by setting the repeat_interval attribute with Oracle’s calendaring expression. A calendaring expression has three main parts: The frequency. Specify a frequency is mandatory. The repeat interval Specifiers which provide detailed information about when the job should be run If you want to create a job that runs every hour, every two weeks, every 30 days, every 5 minutes, or even every second, you can do this by using a combination of the frequency and interval. For example: Every hour: FREQ=HOURLY; INTERVAL=1 Every two weeks: FREQ=WEEKLY; INTERVAL=2 Every 30 days: FREQ=DAILY; INTERVAL=30 Every 5 minutes: FREQ=MINUTELY; INTERVAL=5 Every second: FREQ=SECONDLY If you need to specify a more complex repeat interval, such as every 15th day of the month, every 4th week on Monday, or 6:23 am every Tuesday, then you will need to use the BY* clauses to provide this additional information. For example: Every 15th day of the month: FREQ=MONTHLY; BYMONTHDAY=15 Every 4th week on Monday: FREQ=YEARLY; BYWEEKNO=4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52; BYDAY=MON 6:23 am every Tuesday: FREQ=WEEKLY; BYDAY=TUE; BYHOUR=6; BYMINUTE=23 Frequency Interval Specifiers

9 Advanced Scheduler Components
Job Class Window Schedule Program Job The program determines what should be run. Every automated job involves a particular executable, whether this is a PL/SQL stored procedure, a native binary executable, or a shell script. For the scheduler, a program is a collection of metadata about a particular executable. You can also specify a list of arguments for a program. A job is the combination of a schedule and a program along with any additional arguments required by the program. All job names are of the form [schema.]name. When you create a job, you specify the job name, program information, schedule information, and any other job characteristics, such as: A job class defines a category of jobs that share common resource usage requirements and other characteristics. At any given time, each job can belong to only a single job class. A job class has the following attributes: A database service name. The jobs in the job class will have affinity to the particular service specified, meaning the jobs will run on the instances that the cater the specified service. A resource consumer group, which classifies a set of user sessions that have common resource processing requirements. At any given time, a user session or job class can belong to a single resource consumer group. The resource consumer group that the job class associates with determines the resources that are allocated to the job class. A window is represented by an interval of time with a well-defined beginning and end and is used to activate different resource plans at different times. Arguments Arguments

10 What is a Job Class? APPL_JOBS Job1 Job2 ADMIN_JOBS Job4 Job5 OTHER
A job class defines a category of jobs that share common resource usage requirements, and other characteristics. At any given time, each job belongs to a single job class. A class can belong to a single resource consumer group and a single service at any given time. Consider the following example: The ADMIN_JOBS job class contains jobs performed by the DBA, such as taking backups, rebuilding indexes, and reorganizing tables. These jobs require a lot of resources, but must finish within a certain window of time. To lessen the impact on the production system, these jobs run at night. In order to ensure they finish on time, these jobs require the highest amount of resources during the night hours. During the day, there are more users on the system who are using applications that access the database. Jobs that help to ensure a high level of performance for these applications, such as updating table statistics in the database, are assigned to the APPL_JOBS job class. Since it is critical for the applications to function at the highest possible performance level during day light hours, the jobs in this class need more system resources during this time period. By associating a job with a job class, you can manage the amount of resources the job can use during its execution.

11 Resource Consumer Group
What is a Job Class? Resource Consumer Group Service Log Purge Policy Logging Level Job Class EXECUTE DBMS_SCHEDULER.CREATE_JOB_CLASS( - job_class_name => 'ADMIN_JOBS', - resource_consumer_group => 'DAYTIME_JOBS', - service => 'SERVICE_B'); Use the CREATE_JOB_CLASS procedure of the DBMS_SCHEDULER package to create a job class. A class always belongs to the SYS schema. Creating a class requires the MANAGE SCHEDULER privilege. When creating a job class you can specify the following: Job class name Resource consumer group for the job class Service name for the job class The purge policy for the job class A comment Once a job class has been created, you can specify jobs as members of this job class when you create the jobs, or after the jobs are created by using the SET_ATTRIBUTE procedure. It is not practical to manage resource allocation at an individual job level, therefore, the Scheduler uses the concept of job classes to manage resource allocation among jobs. Resource allocation is specified by mapping a job class to a consumer group. The consumer group that a job class maps to can be specified when creating a job class or at a later time with the SET_ATTRIBUTE procedure of DBMS_SCHEDULER. If no resource consumer group is specified when a job class is created, the job class will map to the default consumer group. There is a default job class that is created with the database. If no job class is associated with a job, then the job belongs to this default job class. The log purge policy specifies the policy for purging of Scheduler log table entries pertaining to jobs belonging to this class. By default, log table entries are not purged. Since all Scheduler activity is logged in the job log, this information accumulates over time and may need to be purge routinely. You can accomplish this by specifying a log purge policy at the job class level.

12 Scheduler Components V V V V V Job Window Group Window Schedule
Resource Plan A window group represents a list of windows. A window or window group is also a valid schedule for a job. You should use a window or window group as the schedule of a job if you want to ensure that the job runs only when a particular resource plan is active.

13 Window Concepts V V V Window Resource Plan Window Group
A window represents a period of time for which specific resource parameters are specified. The window is represented by an interval of time with a well-defined beginning and end. For example, "every day, from 12:00 am to 6:00 am" would represent a valid interval. A window is described as open if it is in effect. Only one window can be in effect at any given time. A system-wide resource plan can be associated with a window and manages the overall resource usage for jobs as well as other sessions run within the window. You can manually set the resource plan using an ALTER SYSTEM command, if you have the necessary privileges. If a resource plan is associated with a window, the scheduler must switch the database to this resource plan when the window opens. When the window closes, the scheduler must switch the database back to the resource plan that was in effect before the window opened if no other window is specified. If no resource plan is associated with the window, the resource plan that was in effect before the window opened will continue to be in effect during the window.

14 Using Resource Plans with Windows
Window with Resource Plan Job Class A Consumer Group = CG1 Job Class B Job3 Job4 Job1 Job2 Consumer Group CG1 Default Consumer Group If a consumer group is associated with a class, then all jobs of that class register themselves as running under that consumer group. If no consumer group is specified for a class, all jobs of that class will run under the default consumer group DEFAULT_CONSUMER_GROUP. Because all jobs that run with the database must belong to a job class is the Resource Manager is running, and a job class is always associated with a resource consumer group, resource manager is always able to properly allocate resources among jobs. When a window opens, the scheduler switches the database to the associated resource plan for the window. You can override this behavior with an ALTER SYSTEM SET RESOURCE_MANAGER_PLAN … FORCE command. Consider the situation where you manually switch to another resource plan for some crucial reason (for example, a CEO suddenly wants full control of the database). As long as the crucial situation lasts, you do not want the scheduler to switch to a different resource plan when a window opens up. You can disable the scheduler from switching resource plans by using the FORCE option of the ALTER SYSTEM statement. To allow the scheduler to switch resource plans again once the crucial situation has passed, you use another ALTER SYSTEM command to turn off the FORCE option.

15 Window Group DAY_APPL_MGMT
Window Groups WindowA Plan: RP1 WindowB Plan: RP2 Window Group DAY_MAIN WindowC1 Plan: RP3 WindowC2 Plan: RP4 Window Group DAY_APPL_MGMT Sometimes a DBA needs to schedule jobs when the priority for that class of jobs is high so the jobs can get more resources. For example, a job which rebuilds the indexes for a production application's tables should run only during a specific window when the jobs are given large amounts of resources. Running the index rebuild jobs at other times runs the risk of the jobs not completing, or taking an excessively long time to complete, which would interfere with the throughput of other jobs. To avoid this, specify a window name as a schedule for a job. This ensures that the job is started only when the window in question is active. In a similar manner, a job must be able to specify the set of windows that are suitable for the job to run within. These windows represent the times when the job might get a higher priority and more resources. A window group is a list of such windows. A job can specify a window group as a valid schedule. The job will run when any window that is a member of the window group opens.

16 Prioritizing Jobs within a Window
Daytime Window APPL_JOBS Job1 Job2 OTHER Job3 ADMIN_JOBS Job4 Job5 Job classes are used to categorize jobs. Different job classes have different scheduler resource usage requirements at different times. For a particular window, you may have several classes of jobs running, each with its own resource usage requirements and priorities. The resources available to a job depends on which job class it belongs to. The job class maps to a resource consumer group. The resource plan specifies how much resources each resource consumer group will be allocated. Job priorities are only used to prioritize among jobs in the same class. There is no guarantee that a high priority job in the APPL_JOBS job class gets started before a low priority job in the ADMIN_JOBS job class, even if they share the same schedule. Prioritizing among jobs of different classes is done purely on a class resource allocation basis.

17 Jobs and Services INST1 INST2 INST3 Service_A Service_A Service_B
APPL_JOBS Service_B ADMIN_JOBS Job1 Job2 Job3 Job4 An Oracle instance is represented to clients as a service. An instance can have one or more services associated with it, and each instance is identified by its service name. A service name is a logical representation of a database, which is the way an instance is presented to clients. An instance can be presented as multiple services, and a service can be implemented as multiple database instances. The service name is a string that is the global database name. A job class can have a service associated with it. If no service is specified then there is no service affinity. Any of the database instances within the cluster can run the job. In the graphic shown above, a job in the APPL_JOBS job class can run on any instance identified by the service name SERVICE_A. This includes INST1 and INST2. A job in the ADMIN_JOBS job class can run on either the INST2or INST3 instances, as those isntances are part of SERVICE_B.

18 Scheduler Interface BEGIN DBMS_SCHEDULER.CREATE_JOB(
job_name=>'ADMIN.GET_STATS2', program_name=>'ADMIN.CALC_STATS2', start_date=>'20-NOV AM -07:00', repeat_interval=>'SYSDATE+2/24'); END; / You can use either Oracle supplied PL/SQL packages or the Enterprise Manager (EM) console to create and manage Scheduler components. Note: For details on EM navigation, please refer to the Oracle10i Database Release 1: Reduce Management - General Enhancements eStudy.

19 Q & Q U E S T I O N S A N S W E R S A

20 Reminder – please complete the OracleWorld online session survey Thank you.

21


Download ppt "SCHEDULING IN ORACLE DATABASE 10G"

Similar presentations


Ads by Google