禁用 Oracle 中所有作业的脚本(DBMS_JOB 包)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5586051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 03:12:06  来源:igfitidea点击:

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

oracleplsqloracle10gdbms-job

提问by Cade Roux

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.

我正在寻找禁用所有作业的脚本。现在我在 Toad 中突出显示它们,单击脱机按钮,然后提交更改。必须有一种方法可以在 PL/SQL 中做到这一点。

回答by Justin Cave

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.

如果要阻止所有作业运行,可以更改初始化参数JOB_QUEUE_PROCESSES。如果您将其设置为 0,Oracle 将不会运行任何使用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.

将所有作业设置为在 1 分钟内运行。

回答by Tagar

== For dbms_job jobs:

== 对于 dbms_job 作业:

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:

== 对于 dbms_scheduler 作业:

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

and after maintenance is complete:

维护完成后:

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

回答by Rakesh Nunna

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.

这将禁用所有已启用的 dbms 作业。

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

您也可以修改查询以启用所有禁用项。