DBMS SCHEDULER

DBMS SCHEDULER is a more sophisticated job scheduler introduced in Oracle 10g. The older job scheduler, DBMS_JOB, is still available, is easier to use in simple cases and fit some needs that DBMS_SCHEDULER does not satisfy.

 

Create a job

BEGIN DBMS_SCHEDULER.CREATE_JOB ( job_name => 'my_java_job', job_type => 'EXECUTABLE', job_action => '/usr/bin/java myClass', repeat_interval => 'FREQ=MINUTELY', enabled => TRUE ); END; /
Unlike DBMS_JOB you do not need to commit the job creation for it to be taken into account. As a corollary, if you want to cancel it, you have to remove or disable it (see below).


Remove a job

EXEC DBMS_SCHEDULER.DROP_JOB('my_java_job');


Run a job now

To force immediate job execution:
EXEC dbms_scheduler.run_job('myjob');


Change job attributes

Examples:
EXEC DBMS_SCHEDULER.SET_ATTRIBUTE('WEEKNIGHT_WINDOW', 'duration', '+000 06:00:00');
BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE ('WEEKNIGHT_WINDOW', 'repeat_interval', 'freq=daily;byday=MON, TUE, WED, THU, FRI;byhour=0;byminute=0;bysecond=0'); END;


Enable / Disable a job

BEGIN DBMS_SCHEDULER.ENABLE('myjob'); END;
BEGIN DBMS_SCHEDULER.DISABLE('myjob'); END;


Monitoring jobs

SELECT * FROM dba_scheduler_jobs WHERE job_name = 'MY_JAVA_JOB'; SELECT * FROM dba_scheduler_job_log WHERE job_name = 'MY_JAVA_JOB';
Use user_scheduler_jobs and user_scheduler_job_log to only see jobs that belong to your user (current schema).
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s