Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script to disable all jobs in Oracle (DBMS_JOB package)?

I'm looking for a script which disables all the jobs. Right now I highlight them all in Toad, click the take offline button and then commit changes. There has to be a way to do this in PL/SQL.

like image 429
Cade Roux Avatar asked Apr 07 '11 18:04

Cade Roux


People also ask

How do I stop a scheduled job in Oracle?

Stopping running jobs When a job is running and you want to stop it, you can run the STOP_JOB procedure as follows. BEGIN DBMS_SCHEDULER. stop_job (JOB_NAME => 'RMAN_INC'); END; STOP_JOB will attempt to gracefully stop a job.

What is the use of DBMS_SCHEDULER in Oracle?

The DBMS_SCHEDULER package provides a collection of scheduling functions and procedures that are callable from any PL/SQL program.

What is Dbms_job broken?

If a job has been marked as broken with DBMS_JOB. BROKEN, or has been marked as broken by Oracle, Oracle will not attempt to execute the job until the broken status has been removed or the the job has been forced to execute.

How do I turn off a job in SQL Developer?

To Disable a job:SQL> execute dbms_scheduler. disable('owner. job');


3 Answers

If you want to prevent all jobs from running, you can change the initialization parameter JOB_QUEUE_PROCESSES. If you set that to 0, Oracle won't run any jobs scheduled using DBMS_JOB.

You could also mark the jobs broken

BEGIN
  FOR x IN (SELECT * FROM user_jobs)
  LOOP
    dbms_job.broken( x.job, true );
  END LOOP;
END;

which will cause them not to be run (but will allow any jobs created after that point to run normally). To unbreak the jobs

BEGIN
  FOR x IN (SELECT * FROM user_jobs)
  LOOP
    dbms_job.broken( x.job, false, SYSDATE + interval '1' minute);
  END LOOP;
END;

will set all the jobs to run in 1 minute.

like image 178
Justin Cave Avatar answered Sep 19 '22 14:09

Justin Cave


== For dbms_job jobs:

alter system set job_queue_processes=0 scope=both;

For some maintenance may be better/ You may normally want to have some jobs offline and don't want to put them online when you'll be done with maintenance.

== For dbms_scheduler jobs:

exec dbms_scheduler.set_scheduler_attribute('SCHEDULER_DISABLED','TRUE');

and after maintenance is complete:

exec dbms_scheduler.set_scheduler_attribute('SCHEDULER_DISABLED','FALSE');
like image 40
Tagar Avatar answered Sep 19 '22 14:09

Tagar


Please run the below query.

set head off
spool job_disable.sql
select 'execute dbms_scheduler.disable('||''''||owner||'.'||job_name||''''||');' from dba_scheduler_jobs where enabled='TRUE';
spool off;
@job_disable.sql

This will disable all the dbms jobs that are enabled.

You can modify the query to enable all the disabled too.

like image 31
Rakesh Nunna Avatar answered Sep 22 '22 14:09

Rakesh Nunna