Documente Academic
Documente Profesional
Documente Cultură
Eddie Awad
awads.net @eddieawad
company holidays. Control how much CPU each of your running jobs can get. Run Operating System commands from inside the database. Run a job only after a successful completion of other jobs.
database 10g and above. Manipulated through the provided PL/SQL package DBMS_SCHEDULER.
with Oracle 10gR1. Oracle recommends using DBMS_SCHEDULER. DBMS_SCHEDULER is more robust and has many features that DBMS_JOB does not have.
on the completion of another job. Does not have robust resource balancing and flexible scheduling features. Cannot run jobs based on a database event. Does not have a syntax that works the same regardless of the operating system. Cannot run status reports using the data dictionary.
Calendaring syntax Resource manager Job chains External jobs Event-based jobs
A simple job
BEGIN sys.DBMS_SCHEDULER.create_job ( job_name => 'MY_JOB', job_type => 'PLSQL_BLOCK', job_action => 'dbms_lock.sleep(30);', start_date => SYSTIMESTAMP AT TIME ZONE 'US/Pacific', end_date => NULL, repeat_interval => NULL, job_class => 'DEFAULT_JOB_CLASS', comments => 'This is a sample job.', auto_drop => FALSE, enabled => TRUE); END; /
The Calendar
Has a very powerful calendaring syntax. Used in the repeat_interval attribute. Results in a set of timestamps.
BYSETPOS=-1
Run on the last workday of every month, assuming that workdays
EXCLUDE=COMPANY_HOLIDAYS; BYSETPOS=-1
Run on the last workday of every month, excluding company
holidays.
FREQ=YEARLY; BYDAY=FRI;BYHOUR=12;
INCLUDE=COMPANY_HOLIDAYS
INTERSECT=LAST_SAT,END_QTR
quarter
Run on the last day of the month that is either a Saturday or last day of a
schedule the job. Tells you what the next execution date and time of a job will be.
DEMO
Create a resource plan and consumer groups. Create a Scheduler Window and associate it with the resource plan. Create Scheduler job classes and associate each with a consumer group. Create Scheduler jobs and associate each with a Scheduler job class.
DEMO
Chains
A job chain is the means by which you can
implement dependency based scheduling, in which jobs are started depending on the outcomes of one or more previous jobs. A job chain consists of multiple steps. A job chain uses rules to describe the relationship between these steps.
Create a Chain
1. 2. 3. 4. 5. 6.
Create Scheduler program objects for each step of the chain (If steps point to programs). Create a chain object. Define the steps in the chain. Define the rules for the chain. Enable the chain. Create a job (the "chain job") that points to the chain.
DEMO
External Jobs
Local external job Its executable runs on the same computer as the database that schedules the job. Remote external jobs (New in 11g) Its executable runs on a remote host. The remote host does not need to have an Oracle database. Must install a Scheduler agent on the remote host and register it with the local database. Use a Scheduler credential object (New in 11g)
External Jobs
Default Authentication when Credentials are not Present
Unix 10.2.0.2+: As the user and group set in $ORACLE_HOME/rdbms/admin/externaljob.ora. Prior to 10.2.0.2: As the owner and group of the file $ORACLE_HOME/bin/extjob. Windows As the user that the OracleJobScheduler Windows service runs as. Unix and Windows, all releases External jobs in the SYS schema run as the user who installed the Oracle Database.
DEMO
Event-Based Jobs
A job can raise one or more pre-defined events. A job can be triggered based on real-time events.
Raising Events
Instruct a job to raise one or more events by setting its
raise_events attribute. The Scheduler raises these events by enqueuing messages onto the Scheduler event queue SYS.SCHEDULER$_EVENT_QUEUE
Raising Events
job_all_events job_broken job_chain_stalled job_completed job_disabled job_failed job_over_max_dur job_run_completed job_sch_lim_reached job_started job_stopped job_succeeded
queue_spec:
includes the name of the queue where your application enqueues messages to raise job start events or in the case of a secure queue, the queue name followed by a comma and the agent name.
event_condition:
A conditional expression based on message properties that must evaluate to TRUE for the message to start the job. The expression must have the syntax of an Oracle Streams Advanced Queuing rule.
DEMO
Resources
PL/SQL Packages and Types Reference (11.2) - DBMS_SCHEDULER: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16760/d_sched.htm Administrator's Guide (11.2) - Scheduling Jobs with Oracle Scheduler: http://download.oracle.com/docs/cd/E11882_01/server.112/e17120/scheduse.htm Oracle Scheduler Forum: http://forums.oracle.com/forums/forum.jspa?forumID=193 Book: Mastering Oracle Scheduler in Oracle 11g Databases: http://www.amazon.com/Mastering-Oracle-Scheduler-11g-Databases/dp/1847195989