High Availbility

OS & Virtualization

Sunday, September 10, 2006

Scheduling Jobs in Oracle

Scheduling jobs in Oracle can be done either thru SQLPLUS or OEM.
A example of scheduling a job is

SQL> VARIABLE jobno number;
SQL> BEGIN - Run the job every 10 minutes
DBMS_JOB. SUBMIT (: jobno, ' create_date_log_row; ' , SYSDATE, ' (SYSDATE + l/(24*6) ) ');
commit ,

END;
/
SQL> print jobno

There is a job_queue_processes which you must set the value greater than 0 or else the job will not run. In Oracle 8i, by default this value is 0, starting Oracle 9i this value is 10.

To start the job scheduler once the database is open, use the ALTER SYSTEM command:
SQL> ALTER SYSTEM SET job_queue_processes = 2;

How do you remove the jobs you don't need?
SQL> EXEC DBMS_Job.Remove(X);
COMMIT;<-- remember to commit

To temporary disable jobs from running
SQL> EXEC DBMS_JOBS.BROKEN(23, TRUE);
To enable
SQL> EXEC DBMS_JOB.BROKEN(23, FALSE, SYSDATE);

  • If you want the job to run every six hours, use the interval SYSDATE + 1/4.
  • If you want the job to run every hour, use the interval SYSDATE + 1/24.
  • If you want the job to run every half hour, use the interval SYSDATE + 1/48.
  • If you want the job to run every 15 minutes, use the interval SYSDATE + 1/96.
  • If you want the job to run every minute, use the interval SYSDATE + 1/1440.

    Of coz, you can also schedule jobs using Operating System. For Windows = Task scheduler, for Linux = Crontab

1 comment:

Tim said...

I dont know why but I still like cron better than the Oracle job schedulers. In part because I can write my scripts to gather key statistics before the job runs (load, disk utilization, etc), log it to the file, and then run sql plus logging its output to the same file.

I also like to email myself emails with different subjects based on the success or failure of the script. I did a little writeup on how I call PL/SQL from a BASH script at:
http://timarcher.com/?q=node/48

Hopefully it helps you!