Oracle - Advanced Queue & Job
Contents
Advanced Queueing
Oracle Advanced Queueing (AQ)
, AQ provides a message queuing infrastructure as integral part of the Oracle server engine. It provides an API for enqueing messages to database queues. These messages can later be dequeued for asynchronous processing.Oracle AQ
also provides functionality to preserve, track, document, correlate, and query messages in queues.
How to Implement
AQ implementation of workflows: A->B->C->D
AQ implementation of Publish/Subscribe:
- point-point:
- publish/subscribe:
- publish/subscribe with rule:
Related packages
From a
PL/SQL
standpoint,Oracle AQ
is made available through two packages:DBMS_AQADM
andDBMS_AQ
. TheDBMS_AQADM
package is the interface to the administrative tasks of Oracle AQ.
DBMS_AQADM
tasks include:
- Creating or dropping queue tables, which contain one or more queues
- Creating, dropping, and altering queues, which are stored in a queue table
Starting and stopping queues in accepting message creation or consumption
Most users of the Oracle AQ facility will not work withDBMS_AQADM
. The DBA will most likely initialize all needed queue tables and queues. PL/SQL developers will instead work with theDBMS_AQ
.
DBMS_AQ
tasks include:
- Creating a message to the specified queue
- Consuming a message from the specified queue
AQ Example
Prepare database user
1 | CONN / AS SYSDBA |
Create a queue
1 | CONN testq/x@ora10gtest |
Test Enqueue
1 | DECLARE |
Test Dequeue
1 | DECLARE |
Job
Overview
Starting with Oracle Database 10g, the Oracle scheduler was greatly improved with the
dbms_scheduler
package. Replacing thedbms_job
withdbms_scheduler
offers additional features by adding the ability to tie jobs with specificuser-type
privileges and roles:
What’s the different
Create job
1 | -- Old using dbms_job scheduler. |
- Define a meaningful
job_name
for the new job.- Assign a
job_action
ofPLSQL_BLOCK
.- Use the what value from the old job as the
job_action
value in the new job.- Use
SYSTIMESTAMP
for the start_date value.- Use the interval value from the old job as the
repeat_interval
value in the new job, making sure the result of the expression is aTIMESTAMP
not aDATE
.
Once this conversion has been completed for all jobs, there is freedom from using the old scheduler, so the
job_queue_processes
parameter can now be set to zero.
Alter job
1 | -- Old using dbms_job scheduler. |
Remove job from queue
1 | -- Old using dbms_job scheduler. |
Related tables
DBA_SCHEDULER_SCHEDULES
- provides me with information about the schedules that are in effect in the database.DBA_SCHEDULER_PROGRAMS
- shows all program objects and their attributes, while viewDBA_SCHEDULER_PROGRAM_ARGS
shows all program arguments for programs that have them.DBA_SCHEDULER_JOBS
- shows all job objects and their attributes.
Resources:
https://docs.oracle.com/cd/E11882_01/server.112/e11013/aq_intro.htm#ADQUE0100
http://www.orafaq.com/wiki/Advanced_Queueing
https://docs.oracle.com/cd/E11882_01/server.112/e25494/scheduse.htm#ADMIN12392
http://www.dba-oracle.com/t_dbms_job_scheduler.htm
Author: itabas016
Link: https://tech.itabas.com/2016/11/04/database/oracle-kt-advanced-queue-job/
License: CC BY-NC-ND 4.0