Sie sind auf Seite 1von 34

ORACLE

JOBS AND SCHEDULES

Ivana Sasínová
10. 1. 2008
Oracle Scheduler
 collection of functions and procedures
in the DBMS_SCHEDULER package
 enables to control when and where
various tasks take place in the
database environment
Oracle Scheduler
 Schedule job execution based on time
or events
 Manage with priorities
 Manage and monitor jobs
Job managing and monitoring
 Scheduler activity logged
 information about jobs and their
execution stored in views and can be
easily queried using Enterprise Manager
or a SQL query
Executing and managing
jobs in a clustered environment
 cluster = set of database instances that
cooperates to perform the same task
 Real Application Clusters (RAC) =
Oracle technology enabling executing and
managing jobs in cluster environment
 possibility to specify the database service
where a job has to run (better
performance, load balancing)
Oracle Scheduler
 most components are database
objects like table
 elements:
 Programs, Chains
 Schedules

 Jobs, Job classes, External Jobs

 Events
Scheduler - Basic elements
Programs
 program object = collection of metadata
(name, program action, program type,
number of arguments)
 invoked by jobs
 different jobs can use the same program and
run it at different times with different settings
 chain = grouping of programs that are linked
together for a single, combined objective
Scheduler - Basic elements
Schedules
 = objects that can be named and saved
in the database
 users can share named schedule
 specify when and how many times a job
is executed
 can specify executing a job when a
certain event occurs
Scheduler - Basic elements
Jobs
 = user-defined tasks that are scheduled to
run one or more times
 job = action + schedule
 creating jobs by:
 specifying action and schedule as job attributes
 specifying names of an existing program object
and schedule object as job attributes
Scheduler - Basic elements
Jobs
 Regular job
 = schema objects (since Oracle Database
11g Release 1)
 maximum flexibility, but entails some
overhead when it is created or dropped
 user has fine-grained control of the
privileges on the job
 can have as its action a program or a
stored procedure owned by another user
Scheduler - Basic elements
Jobs
 Lightweight job
 based on a job template from which
privileges and job metadata is inherited
 not schema objects
 no overhead of creating or dropping
 lower average session creation time than
regular jobs
Scheduler - Basic elements
Jobs
 Regular vs. lightweigt jobs
 regular jobs prefered when:
 relatively small number of jobs that run
infrequently need to be created
 lightweigt jobs prefered when:
 hundreds or thousands of jobs per second need
to be created and dropped
Scheduler - Basic elements
Jobs
 Creating a regular job
(calls a stored procedure in the OPS schema that updates a sales summary table)

BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'update_sales',
job_type => 'STORED_PROCEDURE',
job_action => OPS.SALES_PKG.UPDATE_SALES_SUMMARY',
start_date => '28-APR-03 07.00.00 PM Australia/Sydney',
repeat_interval => 'FREQ=DAILY;INTERVAL=2', /*every other day */
end_date => '20-NOV-04 07.00.00 PM Australia/Sydney',
job_class => 'batch_update_jobs',
comments => 'My new job');
END;
Scheduler - Basic elements
Jobs
 creating a lightweight job
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'my_lightweight_job1',
program_name => 'MY_PROG', /* job template */
repeat_interval => 'FREQ=DAILY;BY_HOUR=9',
end_time => '30-APR-07 04.00.00 AM Australia/Sydney',
job_style => 'LIGHTWEIGHT',
comments => 'New lightweight job based on a program');
END;
Scheduler - Basic elements
Jobs
 Job Template
 = database object
 provides the necessary metadata needed
for running a job
 provides a privilege infrastructure that can
be inherited by any lightweight job
 created based on a Scheduler program
Scheduler - Basic elements
Jobs
 Job arguments
 customize a named program object
 provide argument values to an action that
the job specifies
 a job cannot be enabled until all required
program argument values are defined
Scheduler - Basic elements
Jobs
 Job instance
 represents a specific run of a job
 one entry is added to the Scheduler's job
table when a job is created
 each time the job runs, an entry is added
to the job log
 unique log id
Scheduler - Basic elements
Events
 event = message sent by one application or
system process to another to indicate that
some action or occurrence has been detected
 2 kinds of events:
 raised by Scheduler - indicate state changes that
occur within the Scheduler
 raised by an application - the Scheduler reacts to
the event by starting a job
 Oracle Streams Advanced Queuing used to
raise and consume events by Scheduler
Scheduler - Basic elements
Relationship among programs, jobs,
and schedules
Scheduler – Advanced topics
Job Classes
 Assign the same set of attribute values to
member jobs
 Set service affinity for member jobs
 service attribute
 Set resource allocation for member jobs
 resource_consumer_group attribute
 Group jobs for prioritization
 priority = 1-5
 default priority = 3
 priorities used only among jobs in the same class
Scheduler – Advanced topics
Job Classes
 Prioritizing among jobs of different
classes depends on the resource plan
and on the resource consumer group or
service name of each job class
 Restrictions:
 job must be part of exactly one class
(DEFAULT_JOB_CLASS)
 dropping a class with jobs => error
Scheduler – Advanced topics
External Jobs
 = operating system executables that run
outside the database
 job_type set to EXECUTABLE
 job_action is the path of the external exe
 job arguments set with the
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE
procedure
 run on the host computer as some operating
system user (assign OS credentials)
Scheduler – Advanced topics
External Jobs
 Credential
 = username and password pair stored in a
dedicated database object
 credential_name attribute
 DBMS_SCHEDULER.CREATE_CREDENTIAL
procedure
 can be used only by a job whose owner has
EXECUTE privileges on the credential or is the
owner of the credential
 grant privileges with GRANT SQL statement
Scheduler – Advanced topics
External Jobs
 Local External Job
 run on the same computer as the Oracle
database that schedules it
 destination attribute is null or
localhost
 assigning a credential not required but
recommended
Scheduler – Advanced topics
External Jobs
 Remote External Job
 runs on a computer other than the one running
the Oracle database that schedules it
 remote host may or may not have Oracle
Database installed
 remote host has a Scheduler agent that the
database communicates with
 set a remote host and port as the destination
attribute of the job
 specifying a credential required
Scheduler Architecture
 The Job table
 The Job Coordinator
 Job Slaves
Scheduler Architecture
Scheduler Components
Scheduler Architecture
The Job Table
 container for all the jobs
 one table per database
 information about stored jobs in the
*_SCHEDULER_JOBS views.
 job objects are automatically dropped
after completion (auto_drop job
attribute)
Scheduler Architecture
The Job Coordinator
 background process
 automatically started and stopped as needed
 controls and spawns the job slaves
 queries the job table
 picks up jobs from the job table and places
them in a memory cache
 takes jobs from the memory cache and
passes them to job slaves for execution
Scheduler Architecture
The Job Coordinator
 cleans up the job slave pool when
slaves are no longer needed
 goes to sleep when no jobs are
scheduled
 wakes up when a new job is about to
be executed
 after an abnormal database shutdown
recovers any jobs that were running
Scheduler Architecture
The Job Coordinator
 automatically determines how many job
slaves to start based on CPU load and
the number of outstanding jobs
 one job coordinator per instance (also
in RAC environments)
Scheduler Architecture
Job slaves
 execute the jobs
 awakened by the job coordinator
 execution of a job, a job slave:
 gathers all the metadata needed to run the job
 starts a database session, starts a transaction, and
then starts executing the job
 commits and ends the transaction
 closes the session
Scheduler Architecture
Job slaves
 after the job is done, the job slaves:
 reschedule the job if required
 update the state in the job table (the job has
completed or is scheduled to run again)
 insert an entry into the job log table
 update the run count, failure count, retry count
 clean up
 look for new work (if none, they go to sleep)
Source

 Oracle Database Administrator's Guide


11g Release 1 (11.1)

Das könnte Ihnen auch gefallen