Skip to main content

Disabling and reactivating jobs

When to use it

Before maintenance, a refresh or a migration, when jobs of one schema must not run; and afterwards, to turn them back on.

Run this

Script: 04_disable_all_owner_jobs.sql. Full version in Administration › Scheduler management › Scheduler jobs.

-- ============================================================================
-- Script: Disable All Jobs for a Specific Owner
-- Purpose: Generate DDL commands to disable all DBMS_SCHEDULER jobs
--          owned by a specified user
-- Usage: sqlplus / as sysdba @04_disable_all_owner_jobs.sql
-- ============================================================================

ACCEPT OWNER_NAME PROMPT 'Enter job owner name (leave blank for all owners): '

SET LINESIZE 200
SET PAGESIZE 0
SET FEEDBACK OFF
SET ECHO OFF
SET HEADING OFF
SET VERIFY OFF

COLUMN ddl_command FORMAT A200

-- Generate DBMS_SCHEDULER.DISABLE commands for each job
SELECT 'BEGIN' AS ddl_command
UNION ALL
SELECT '  DBMS_SCHEDULER.DISABLE(''' || owner || '.' || job_name || ''', force => TRUE);'
FROM dba_scheduler_jobs
WHERE 1=1
  AND enabled = 'TRUE'
  AND (UPPER(owner) = NVL(UPPER('&OWNER_NAME'), owner) OR '&OWNER_NAME' IS NULL)
ORDER BY owner, job_name
UNION ALL
SELECT 'END;' AS ddl_command
/

-- Display summary before execution
SET HEADING ON
SET FEEDBACK ON
COLUMN job_count HEADING 'Total Jobs to Disable'

SELECT COUNT(*) AS job_count
FROM dba_scheduler_jobs
WHERE 1=1
  AND enabled = 'TRUE'
  AND (UPPER(owner) = NVL(UPPER('&OWNER_NAME'), owner) OR '&OWNER_NAME' IS NULL);

PROMPT
PROMPT ============================================================================
PROMPT JOBS TO BE DISABLED:
PROMPT ============================================================================

SET HEADING ON
COLUMN owner FORMAT A20
COLUMN job_name FORMAT A40
COLUMN enabled FORMAT A10
COLUMN state FORMAT A15

SELECT
    owner,
    job_name,
    enabled,
    state
FROM dba_scheduler_jobs
WHERE 1=1
  AND enabled = 'TRUE'
  AND (UPPER(owner) = NVL(UPPER('&OWNER_NAME'), owner) OR '&OWNER_NAME' IS NULL)
ORDER BY owner, job_name;

UNDEFINE OWNER_NAME

Script: 08_reactivate_jobs_ddl.sql. Full version in Administration › Scheduler management › Scheduler jobs.

-- ============================================================================
-- Script: Generate DDL to Reactivate Jobs
-- Purpose: Generate commands to enable/reactivate DBMS_SCHEDULER jobs
--          that are in BROKEN or DISABLED state
-- Usage: sqlplus / as sysdba @08_reactivate_jobs_ddl.sql
-- ============================================================================

ACCEPT OWNER_NAME PROMPT 'Enter job owner name (leave blank for all owners): '
ACCEPT JOB_STATE PROMPT 'Job state to reactivate [BROKEN/DISABLED/ALL]: ' DEFAULT 'ALL'

SET LINESIZE 200
SET PAGESIZE 0
SET FEEDBACK OFF
SET ECHO OFF
SET HEADING OFF
SET VERIFY OFF

COLUMN ddl_command FORMAT A200

-- Generate DBMS_SCHEDULER.ENABLE commands to reactivate jobs
SELECT 'BEGIN' AS ddl_command
UNION ALL
SELECT '  DBMS_SCHEDULER.ENABLE(''' || owner || '.' || job_name || ''');'
FROM dba_scheduler_jobs
WHERE 1=1
  AND enabled = 'FALSE'
  AND (UPPER(owner) = NVL(UPPER('&OWNER_NAME'), owner) OR '&OWNER_NAME' IS NULL)
  AND (
      (UPPER('&JOB_STATE') = 'ALL')
      OR (UPPER('&JOB_STATE') = 'BROKEN' AND state = 'BROKEN')
      OR (UPPER('&JOB_STATE') = 'DISABLED' AND state = 'DISABLED')
  )
ORDER BY owner, job_name
UNION ALL
SELECT 'END;' AS ddl_command
/

-- Display summary before execution
SET HEADING ON
SET FEEDBACK ON
COLUMN job_count HEADING 'Total Jobs to Reactivate'

SELECT COUNT(*) AS job_count
FROM dba_scheduler_jobs
WHERE 1=1
  AND enabled = 'FALSE'
  AND (UPPER(owner) = NVL(UPPER('&OWNER_NAME'), owner) OR '&OWNER_NAME' IS NULL)
  AND (
      (UPPER('&JOB_STATE') = 'ALL')
      OR (UPPER('&JOB_STATE') = 'BROKEN' AND state = 'BROKEN')
      OR (UPPER('&JOB_STATE') = 'DISABLED' AND state = 'DISABLED')
  );

PROMPT
PROMPT ============================================================================
PROMPT JOBS TO BE REACTIVATED:
PROMPT ============================================================================

SET HEADING ON
COLUMN owner FORMAT A20
COLUMN job_name FORMAT A40
COLUMN state FORMAT A15
COLUMN enabled FORMAT A10

SELECT
    owner,
    job_name,
    state,
    enabled,
    last_start_date,
    next_run_date
FROM dba_scheduler_jobs
WHERE 1=1
  AND enabled = 'FALSE'
  AND (UPPER(owner) = NVL(UPPER('&OWNER_NAME'), owner) OR '&OWNER_NAME' IS NULL)
  AND (
      (UPPER('&JOB_STATE') = 'ALL')
      OR (UPPER('&JOB_STATE') = 'BROKEN' AND state = 'BROKEN')
      OR (UPPER('&JOB_STATE') = 'DISABLED' AND state = 'DISABLED')
  )
ORDER BY owner, job_name;

UNDEFINE OWNER_NAME
UNDEFINE JOB_STATE

How to read the output

  • Both scripts only generate a BEGIN ... END; block with one line per job. They also show how many jobs are affected and list them.
  • Leaving the owner blank selects jobs of all owners, including Oracle internal jobs. Always enter an owner.
  • The reactivation script asks which state to bring back: BROKEN, DISABLED or ALL.

What to do next

  1. Before disabling, save the list of jobs that are currently enabled. That list is what you will turn back on.
  2. Review the generated block and run it only inside the approved change window.
  3. After the maintenance, reactivate only the jobs from your saved list. Jobs that were already disabled before must stay disabled.
  4. Check the result with "Job run history" after the next scheduled run.

Risk level

GENERATES COMMANDS The script only prints commands. Nothing changes until someone runs that output. Review it line by line first.