Monitoring Jobs
There are several ways to monitor Scheduler jobs:
-
Viewing the job log
The job log includes the data dictionary views
*_SCHEDULER_JOB_LOG
and*_SCHEDULER_JOB_RUN_DETAILS
, where:* = {
DBA
|ALL
|USER
} -
Querying additional data dictionary views
Query views such as
DBA_SCHEDULER_RUNNING_JOBS
andDBA_SCHEDULER_RUNNING_CHAINS
to show the status and details of running jobs and chains. -
Writing applications that receive job state events from the Scheduler
See "Monitoring Job State with Events Raised by the Scheduler"
-
Configuring jobs to send e-mail notifications upon a state change
Viewing the Job Log
You can view information about job runs, job state changes, and job failures in the job log. The job log shows results for both local and remote jobs. The job log is implemented as the following two data dictionary views:
-
*_SCHEDULER_JOB_LOG
-
*_SCHEDULER_JOB_RUN_DETAILS
Depending on the logging level that is in effect, the Scheduler can make job log entries whenever a job is run and when a job is created, dropped, enabled, and so on. For a job that has a repeating schedule, the Scheduler makes multiple entries in the job log—one for each job instance. Each log entry provides information about a particular run, such as the job completion status.
The following example shows job log entries for a repeating job that has a value of 4 for the max_runs
attribute:
SELECT job_name, job_class, operation, status FROM USER_SCHEDULER_JOB_LOG; JOB_NAME JOB_CLASS OPERATION STATUS ---------------- -------------------- --------------- ---------- JOB1 CLASS1 RUN SUCCEEDED JOB1 CLASS1 RUN SUCCEEDED JOB1 CLASS1 RUN SUCCEEDED JOB1 CLASS1 RUN SUCCEEDED JOB1 CLASS1 COMPLETED
You can control how frequently information is written to the job log by setting the logging_level
attribute of either a job or a job class. Table 29-11 shows the possible values for logging_level
.
Table 29-11 Job Logging Levels
Logging Level | Description |
---|---|
|
No logging is performed. |
|
A log entry is made only if the job fails. |
|
A log entry is made each time the job is run. |
|
A log entry is made every time the job runs and for every operation performed on a job, including create, enable/disable, update (with |
Log entries for job runs are not made until after the job run completes successfully, fails, or is stopped.
The following example shows job log entries for a complete job lifecycle. In this case, the logging level for the job class is LOGGING_FULL
, and the job is a non-repeating job. After the first successful run, the job is enabled again, so it runs once more. It is then stopped and dropped.
SELECT to_char(log_date, 'DD-MON-YY HH24:MI:SS') TIMESTAMP, job_name, job_class, operation, status FROM USER_SCHEDULER_JOB_LOG WHERE job_name = 'JOB2' ORDER BY log_date; TIMESTAMP JOB_NAME JOB_CLASS OPERATION STATUS -------------------- --------- ---------- ---------- --------- 18-DEC-07 23:10:56 JOB2 CLASS1 CREATE 18-DEC-07 23:12:01 JOB2 CLASS1 UPDATE 18-DEC-07 23:12:31 JOB2 CLASS1 ENABLE 18-DEC-07 23:12:41 JOB2 CLASS1 RUN SUCCEEDED 18-DEC-07 23:13:12 JOB2 CLASS1 ENABLE 18-DEC-07 23:13:18 JOB2 RUN STOPPED 18-DEC-07 23:19:36 JOB2 CLASS1 DROP
Run Details
For every row in *_SCHEDULER_JOB_LOG
for which the operation is RUN
, RETRY_RUN
, or RECOVERY_RUN
, there is a corresponding row in the *_SCHEDULER_JOB_RUN_DETAILS
view. Rows from the two different views are correlated with their LOG_ID
columns. You can consult the run details views to determine why a job failed or was stopped.
SELECT to_char(log_date, 'DD-MON-YY HH24:MI:SS') TIMESTAMP, job_name, status, SUBSTR(additional_info, 1, 40) ADDITIONAL_INFO FROM user_scheduler_job_run_details ORDER BY log_date; TIMESTAMP JOB_NAME STATUS ADDITIONAL_INFO -------------------- ---------- --------- ---------------------------------------- 18-DEC-07 23:12:41 JOB2 SUCCEEDED 18-DEC-07 23:12:18 JOB2 STOPPED REASON="Stop job called by user:'SYSTEM' 19-DEC-07 14:12:20 REMOTE_16 FAILED ORA-29273: HTTP request failed ORA-06512
The run details views also contain actual job start times and durations.
Precedence of Logging Levels in Jobs and Job Classes
Both jobs and job classes have a logging_level
attribute, with possible values listed in Table 29-11. The default logging level for job classes is LOGGING_RUNS
, and the default level for individual jobs is LOGGING_OFF
. If the logging level of the job class is higher than that of a job in the class, then the logging level of the job class takes precedence. Thus, by default, all job runs are recorded in the job log.
For job classes that have very short and highly frequent jobs, the overhead of recording every single run might be too much and you might choose to turn the logging off or set logging to occur only when jobs fail. However, you might prefer to have a complete audit trail of everything that happens with jobs in a specific class, in which case you would enable full logging for that class.
To ensure that there is an audit trail for all jobs, the individual job creator must not be able to turn logging off. The Scheduler supports this by making the class-specified level the minimum level at which job information is logged. A job creator can only enable more logging for an individual job, not less. Thus, leaving all individual job logging levels set to LOGGING_OFF
ensures that all jobs in a class get logged as specified in the class.
This functionality is provided for debugging purposes. For example, if the class-specific level is set to record job runs and logging is turned off at the job level, the Scheduler still logs job runs. If, however, the job creator turns on full logging and the class-specific level is set to record runs only, the higher logging level of the job takes precedence and all operations on this individual job are logged. This way, an end user can test his job by turning on full logging.
To set the logging level of an individual job, you must use the SET_ATTRIBUTE
procedure on that job. For example, to turn on full logging for a job called mytestjob
, issue the following statement:
BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE ( 'mytestjob', 'logging_level', DBMS_SCHEDULER.LOGGING_FULL); END; /
Only a user with the MANAGE
SCHEDULER
privilege can set the logging level of a job class.
See Also:
"Monitoring and Managing Window and Job Logs" for more information about setting the job class logging level
Monitoring Multiple Destination Jobs
For multiple-destination jobs, the overall parent job state depends on the outcome of the child jobs. For example, if all child jobs succeed, the parent job state is set to SUCCEEDED
. If all fail, the parent job state is set to FAILED
. If some fail and some succeed, the parent job state is set to SOME
FAILED
.
Due to situations that might arise on some destinations that delay the start of child jobs, there might be a significant delay before the parent job state is finalized. For repeating multiple-destination jobs, there might even be a situation in which some child jobs are on their next scheduled run while others are still working on the previous scheduled run. In this case, the parent job state is set to INCOMPLETE
. Eventually, however, lagging child jobs may catch up to their siblings, in which case the final state of the parent job can be determined.
Table Table 29-12 lists the contents of the job monitoring views for multiple-destination jobs.
Table 29-12 Scheduler Data Dictionary View Contents for Multiple-Destination Jobs
View Name | Contents |
---|---|
|
One entry for the parent job |
|
One entry for the parent job when it starts and an entry for each running child job |
|
One entry for the parent job when it starts (operation = ' |
|
One entry for each child job when the child job completes, and one entry for the parent job when the last child job completes and thus the parent completes |
|
One entry for each destination of the parent job |
In the *_SCHEDULER_JOB_DESTS
views, you can determine the unique job destination ID (job_dest_id
) that is assigned to each child job. This ID represents the unique combination of a job, a credential, and a destination. You can use this ID with the STOP_JOB
procedure. You can also monitor the job state of each child job with the *_SCHEDULER_JOB_DESTS
views.
See Also:
Monitoring Job State with Events Raised by the Scheduler
This section contains:
About Job State Events
You can configure a job so that the Scheduler raises an event when the job changes state. The Scheduler can raise an event when a job starts, when a job completes, when a job exceeds its allotted run time, and so on. The consumer of the event is your application, which takes some action in response to the event. For example, if due to a high system load, a job is still not started 30 minutes after its scheduled start time, the Scheduler can raise an event that causes a handler application to stop lower priority jobs to free up system resources. The Scheduler can raise job state events for local (regular) jobs, remote database jobs, local external jobs, and remote external jobs.
Table 29-13 describes the job state event types raised by the Scheduler.
Table 29-13 Job State Event Types Raised by the Scheduler
Event Type | Description |
---|---|
|
Not an event, but a constant that provides an easy way for you to enable all events |
|
The job has been disabled and has changed to the |
|
A job running a chain was put into the |
|
The job completed because it reached its |
|
The job was disabled by the Scheduler or by a call to |
|
The job failed, either by throwing an error or by abnormally terminating |
|
The job exceeded the maximum run duration specified by its |
|
A job run either failed, succeeded, or was stopped |
|
The job's schedule limit was reached. The job was not started because the delay in starting the job exceeded the value of the |
|
The job started |
|
The job was stopped by a call to |
|
The job completed successfully |
You enable the raising of job state events by setting the raise_events
job attribute. By default, a job does not raise any job state events.
The Scheduler uses Oracle Streams Advanced Queuing to raise events. When raising a job state change event, the Scheduler enqueues a message onto a default event queue. Your applications subscribe to this queue, dequeue event messages, and take appropriate actions.
After you enable job state change events for a job, the Scheduler raises these events by enqueuing messages onto the Scheduler event queue SYS.SCHEDULER$_EVENT_QUEUE
. This queue is a secure queue, so depending on your application, you may have to configure the queue to enable certain users to perform operations on it. See Oracle Streams Concepts and Administration for information on secure queues.
To prevent unlimited growth of the Scheduler event queue, events raised by the Scheduler expire in 24 hours by default. (Expired events are deleted from the queue.) You can change this expiry time by setting the event_expiry_time
Scheduler attribute with the SET_SCHEDULER_ATTRIBUTE
procedure. See Oracle Database PL/SQL Packages and Types Reference for more information.
Altering a Job to Raise Job State Events
To enable job state events to be raised for a job, you use the SET_ATTRIBUTE
procedure to turn on bit flags in the raise_events
job attribute. Each bit flag represents a different job state to raise an event for. For example, turning on the least significant bit enables job
started
events to be raised. To enable multiple state change event types in one call, you add the desired bit flag values together and supply the result as an argument to SET_ATTRIBUTE
.
The following example enables multiple state change events for job dw_reports
. It enables the following event types, both of which indicate some kind of error.
-
JOB_FAILED
-
JOB_SCH_LIM_REACHED
BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE('dw_reports', 'raise_events', DBMS_SCHEDULER.JOB_FAILED + DBMS_SCHEDULER.JOB_SCH_LIM_REACHED); END; /
Note:
You do not need to enable the JOB_OVER_MAX_DUR
event with the raise_events
job attribute; it is always enabled.
See Also:
The discussion of DBMS_SCHEDULER
.SET_ATTRIBUTE
in Oracle Database PL/SQL Packages and Types Reference for the names and values of job state bit flags
Consuming Job State Events with your Application
To consume job state events, your application must subscribe to the Scheduler event queue SYS.SCHEDULER$_EVENT_QUEUE
. This queue is a secure queue and is owned by SYS
. To create a subscription to this queue for a user, do the following:
-
Log in to the database as the
SYS
user or as a user with theMANAGE
ANY
QUEUE
privilege. -
Subscribe to the queue using a new or existing agent.
-
Run the package procedure
DBMS_AQADM.ENABLE_DB_ACCESS
as follows:DBMS_AQADM.ENABLE_DB_ACCESS(agent_name, db_username);
where
agent_name
references the agent that you used to subscribe to the events queue, anddb_username
is the user for whom you want to create a subscription.
There is no need to grant dequeue privileges to the user. The dequeue privilege is granted on the Scheduler event queue to PUBLIC
.
As an alternative, the user can subscribe to the Scheduler event queue using the ADD_EVENT_QUEUE_SUBSCRIBER
procedure, as shown in the following example:
DBMS_SCHEDULER.ADD_EVENT_QUEUE_SUBSCRIBER(subscriber_name);
where subscriber_name
is the name of the Oracle Streams Advanced Queuing (AQ) agent to be used to subscribe to the Scheduler event queue. (If it is NULL
, an agent is created whose name is the user name of the calling user.) This call both creates a subscription to the Scheduler event queue and grants the user permission to dequeue using the designated agent. The subscription is rule-based. The rule permits the user to see only events raised by jobs that the user owns, and filters out all other messages. After the subscription is in place, the user can either poll for messages at regular intervals or register with AQ for notification.
See Oracle Streams Advanced Queuing User's Guide for more information.
The Scheduler event queue SYS.SCHEDULER$_EVENT_QUEUE
is of type scheduler$_event_info
. See Oracle Database PL/SQL Packages and Types Reference for details on this type.
Monitoring Job State with E-mail Notifications
This section contains:
About E-mail Notifications
You can configure a job to send e-mail notifications when it changes state. The job state events for which e-mails can be sent are listed in Table 29-13. E-mail notifications can be sent to multiple recipients, and can be triggered by any event in a list of job state events that you specify. You can also provide a filter condition, and only job state events that match the filter condition generate notifications. You can include variables like job owner, job name, event type, error code, and error message in both the subject and body of the message. The Scheduler automatically sets values for these variables before sending the e-mail notification.
You can configure many job state e-mail notifications for a single job. The notifications can differ by job state event list, recipients, and filter conditions.
For example, you can configure a job to send an e-mail to both the principle DBA and one of the senior DBAs whenever the job fails with error code 600 or 700. You can also configure the same job to send a notification to only the principle DBA if the job fails to start at its scheduled time.
Before you can configure jobs to send e-mail notifications, you must set the Scheduler attribute email_server
to the address of the SMTP server to use to send the e-mail. You may also optionally set the Scheduler attribute email_sender
to a default sender e-mail address for those jobs that do not specify a sender.
The Scheduler includes support for the SSL and TLS protocols when communicating with the SMTP server. The Scheduler also supports SMTP servers that require authentication.
See Also:
"Setting Scheduler Preferences" for details about setting e-mail notification–related attributes
Adding E-mail Notifications for a Job
You use the DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION
package procedure to add e-mail notifications for a job.
BEGIN DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION ( job_name => 'EOD_JOB', recipients => 'jsmith@example.com, rjones@example.com', sender => 'do_not_reply@example.com', subject => 'Scheduler Job Notification-%job_owner%.%job_name%-%event_type%', body => '%event_type% occurred at %event_timestamp%. %error_message%', events => 'JOB_FAILED, JOB_BROKEN, JOB_DISABLED, JOB_SCH_LIM_REACHED'); END; /
Note the variables, enclosed in the '%' character, used in the subject
and body
arguments. When you specify multiple recipients and multiple events, each recipient is notified when any of the specified events is raised. You can verify this by querying the view USER_SCHEDULER_NOTIFICATIONS
.
SELECT JOB_NAME, RECIPIENT, EVENT FROM USER_SCHEDULER_NOTIFICATIONS; JOB_NAME RECIPIENT EVENT ----------- -------------------- ------------------- EOD_JOB jsmith@example.com JOB_FAILED EOD_JOB jsmith@example.com JOB_BROKEN EOD_JOB jsmith@example.com JOB_SCH_LIM_REACHED EOD_JOB jsmith@example.com JOB_DISABLED EOD_JOB rjones@example.com JOB_FAILED EOD_JOB rjones@example.com JOB_BROKEN EOD_JOB rjones@example.com JOB_SCH_LIM_REACHED EOD_JOB rjones@example.com JOB_DISABLED
You call ADD_JOB_EMAIL_NOTIFICATION
once for each different set of notifications that you want to configure for a job. You must specify job_name
and recipients
. All other arguments have defaults. The default sender
is defined by a Scheduler attribute, as described in the previous section. See the ADD_JOB_EMAIL_NOTIFICATION
procedure in Oracle Database PL/SQL Packages and Types Reference for defaults for the subject
, body
, and events
arguments.
The following example configures an additional e-mail notification for the same job for a different event. This example accepts the defaults for the sender
, subject
, and body
arguments.
BEGIN DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION ( job_name => 'EOD_JOB', recipients => 'jsmith@example.com', events => 'JOB_OVER_MAX_DUR'); END; /
This example could have also omitted the events
argument to accept event defaults.
The next example is similar to the first, except that it uses a filter condition to specify that an e-mail notification is to be sent only when the error number that causes the job to fail is 600 or 700.
BEGIN DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION ( job_name => 'EOD_JOB', recipients => 'jsmith@example.com, rjones@example.com', sender => 'do_not_reply@example.com', subject => 'Job Notification-%job_owner%.%job_name%-%event_type%', body => '%event_type% at %event_timestamp%. %error_message%', events => 'JOB_FAILED', filter_condition => ':event.error_code=600 or :event.error_code=700'); END; /
See Also:
The ADD_JOB_EMAIL_NOTIFICATION
procedure in Oracle Database PL/SQL Packages and Types Reference
Removing E-mail Notifications for a Job
You use the DBMS_SCHEDULER.REMOVE_JOB_EMAIL_NOTIFICATION
package procedure to remove e-mail notifications for a job.
BEGIN DBMS_SCHEDULER.REMOVE_JOB_EMAIL_NOTIFICATION ( job_name => 'EOD_JOB', recipients => 'jsmith@example.com, rjones@example.com', events => 'JOB_DISABLED, JOB_SCH_LIM_REACHED'); END; /
When you specify multiple recipients and multiple events, the notification for each specified event is removed for each recipient. Running the same query as that of the previous section, the results are now the following:
SELECT JOB_NAME, RECIPIENT, EVENT FROM USER_SCHEDULER_NOTIFICATIONS; JOB_NAME RECIPIENT EVENT ----------- -------------------- ------------------- EOD_JOB jsmith@example.com JOB_FAILED EOD_JOB jsmith@example.com JOB_BROKEN EOD_JOB rjones@example.com JOB_FAILED EOD_JOB rjones@example.com JOB_BROKEN
Additional rules for specifying REMOVE_JOB_EMAIL_NOTIFICATION
arguments are as follows:
-
If you leave the
events
argumentNULL
, notifications for all events for the specified recipients are removed. -
If you leave
recipients
NULL
, notifications for all recipients for the specified events are removed. -
If you leave both
recipients
andevents
NULL
, then all notifications for the job are removed. -
If you include a recipient and event for which you did not previously create a notification, no error is generated.
See Also:
The REMOVE_JOB_EMAIL_NOTIFICATION
procedure in Oracle Database PL/SQL Packages and Types Reference
Viewing Information About E-mail Notifications
As demonstrated in the previous sections, you can view information about current e-mail notifications by querying the views *_SCHEDULER_NOTIFICATIONS
.
See Also:
Oracle Database Reference for details on these views