9 Job Scheduling And Automation

Database Administration · Unit 9

Job Scheduling and Automation

Exam-focused notes for Job Scheduling and Automation (Database Administration, BIT352): what the TU syllabus asks and how it has actually been tested, with 4 solved past questions from this unit.

Job Scheduling and Automation in short

Many DBA tasks repeat: backups, statistics, cleaning old data and reports. The Oracle Scheduler runs them automatically, so the DBA does not have to start each one by hand.

Job Scheduling and Automation: notes

Job scheduling in oracle database

Job scheduling means running a task at a set time, at a repeat interval or when an event happens. Oracle has two tools.

  • DBMS_JOB: the old package, kept for compatibility.
  • DBMS_SCHEDULER: the newer and stronger package, which should be used now.

Advantages of the Scheduler over the old package:

  • Runs PL/SQL blocks, stored procedures and operating system programs.
  • Repeat rules are rich and use a calendar syntax.
  • Jobs can start from events.
  • Job logs and history are kept.
  • Resources can be controlled using job classes and windows.

The user needs the CREATE JOB privilege.

DBMS_SCHEDULER functionality

DBMS_SCHEDULER has procedures to create, run, change and remove objects.

ProcedureUse
CREATE_JOBMake a job
CREATE_PROGRAMMake a program
CREATE_SCHEDULEMake a schedule
CREATE_JOB_CLASSMake a job class
RUN_JOBRun a job now
ENABLE / DISABLETurn an object on or off
SET_ATTRIBUTEChange a setting
STOP_JOBStop a running job
DROP_JOBRemove a job

A simple job that runs a PL/SQL block every day at 2 a.m.:

BEGIN
  DBMS_SCHEDULER.CREATE_JOB(
    job_name        => 'GATHER_STATS_JOB',
    job_type        => 'PLSQL_BLOCK',
    job_action      => 'BEGIN DBMS_STATS.GATHER_SCHEMA_STATS(''SCOTT''); END;',
    start_date      => SYSTIMESTAMP,
    repeat_interval => 'FREQ=DAILY; BYHOUR=2; BYMINUTE=0',
    enabled         => TRUE);
END;
/

What this unit covers

  • Job scheduling in oracle database
  • DBMS_SCHEDULER functionality
  • Scheduler components
  • Schedule definition and creation
  • Job and job classes
  • Program definition and relationship
  • Event-based schedule creation
  • Schedule, job and program relationships

Event-based schedule creation

2081 · 5 marks

How event based schedules are created? Explain. [5]

An event-based schedule (also called an event-driven schedule) is a scheduling approach where task execution is triggered by the occurrence of specific events rather than by a fixed time interval or clock tick. The scheduler responds to events as they happen in real time. --- The first step is to...

Open this answer on its own page →

Job scheduling in oracle database

2080 · 5 marks

What is Job Scheduling in oracle database? How DBMS_ SCHEDULER Works? Explain the different component of scheduler. [5]

Note: Reference notes were not available for this topic. The following answer is based on standard Oracle Database documentation and is correct for TU BSc CSIT curriculum. --- Job Scheduling in Oracle Database is the process of automating the execution of database tasks (jobs) at specified times,...

Open this answer on its own page →

Job and job classes

2081.1 · 5 marks

What is Job and Job classes? Create an event-based schedule in Oracle. [5]

Show solved answer

Jobs and Job Classes in Oracle Scheduler

What is a Job?

A Job is a scheduled task or unit of work that Oracle Scheduler executes at a specified time or interval. A job defines:

  • What to run (a PL/SQL block, stored procedure, or executable)
  • When to run (a schedule or specific time)
  • How to run (priority, logging level, etc.)

What is a Job Class?

A Job Class is a logical grouping of jobs that share common attributes such as:

  • Resource consumer group (for resource management)
  • Service name (which database service to use)
  • Logging level (how much logging to perform)
  • Priority among jobs within the same window

Job classes allow DBAs to manage and prioritize groups of jobs collectively rather than individually.


Creating an Event-Based Schedule in Oracle

An event-based schedule triggers a job when a specific event occurs (e.g., a message is enqueued into an Oracle Advanced Queue), rather than at a fixed time.

Step 1: Create an Event Queue (Advanced Queue)

-- Create a queue table
BEGIN
  DBMS_AQADM.CREATE_QUEUE_TABLE(
    queue_table        => 'event_queue_table',
    queue_payload_type => 'SYS.SCHEDULER$_EVENT_INFO'
  );
END;
/

-- Create the queue
BEGIN
  DBMS_AQADM.CREATE_QUEUE(
    queue_name  => 'my_event_queue',
    queue_table => 'event_queue_table'
  );
END;
/

-- Start the queue
BEGIN
  DBMS_AQADM.START_QUEUE(queue_name => 'my_event_queue');
END;
/

Step 2: Create the Event-Based Schedule

BEGIN
  DBMS_SCHEDULER.CREATE_SCHEDULE(
    schedule_name   => 'my_event_schedule',
    event_condition => 'tab.user_data.event_type = ''MY_EVENT''',
    queue_spec      => 'my_event_queue'
  );
END;
/

Step 3: Create a Job Using the Event-Based Schedule

BEGIN
  DBMS_SCHEDULER.CREATE_JOB(
    job_name        => 'my_event_job',
    job_type        => 'STORED_PROCEDURE',
    job_action      => 'my_procedure',
    schedule_name   => 'my_event_schedule',
    enabled         => TRUE,
    comments        => 'Job triggered by an event'
  );
END;
/
BEGIN
  DBMS_SCHEDULER.CREATE_JOB_CLASS(
    job_class_name          => 'my_job_class',
    resource_consumer_group => 'DEFAULT_CONSUMER_GROUP',
    logging_level           => DBMS_SCHEDULER.LOGGING_FULL,
    comments                => 'Job class for event-based jobs'
  );
END;
/

Summary Table

ConceptDescription
JobA scheduled unit of work (what + when + how)
Job ClassA group of jobs sharing common resource/logging attributes
Event-Based ScheduleA schedule triggered by an event (queue message) rather than time

Note: The DBMS_SCHEDULER package is the standard Oracle utility used to create and manage jobs, job classes, and schedules.

Open this answer on its own page →

Schedule, job and program relationships

0 · 5 marks

Explain relationship between schedule, job and program. Create a Schedule in oracle. [5]

In Oracle DBMS (specifically Oracle Scheduler), Schedule, Job, and Program are three distinct but closely related objects used to automate database tasks. --- - A Program defines what to do (the action/task to be executed). - It encapsulates the executable unit: a PL/SQL block, stored procedure, ...

Open this answer on its own page →