By Kamran Agayev Agamehdi
The
dba_scheduler_job_log view
can be used to view log entries for previously executed jobs. This view
displays log information for all dbms_scheduler
jobs in the database. When creating a job, we define log_history parameter and logs in that view are available for number
of days as it specified in
log_history parameter (default is 30)
One of the main columns in
dba_scheduler_job_log
is the STATUS column. This column
gives us the status of the operation.
Possible values for this column are dependent on the value in the
OPERATION column. In most cases, STATUS will be NULL. Only for job run
operations will it have a value.
-
STATUS will be NULL when OPERATION is one of the following:
-
CREATE - Job was created
-
UPDATE - One or more job attributes have been modified
-
ENABLE - Job has been enabled
-
DISABLE - Job has been disabled
-
COMPLETED - For repeating jobs only, job has reached its end date or
maximum number of runs
-
BROKEN - Job has reached its maximum number of failures
STATUS can be SUCCEEDED (job run completed successfully), FAILED (job
run failed), or STOPPED (job run was stopped) when OPERATION is one of
the following:
-
run - Regular job run
-
retry_run
- Job is being retried because the previous run resulted in an error
and RESTARTABLE is set to TRUE
-
recovery_run
- Job is being rerun because the database went down, or the job
slave crashed and RESTARTABLE is set to TRUE
Let's test the use of
dba_scheduler_job_log
step-by-step. In below example, we create a table and a
job which will run every minute and insert one row in that table.
We will set logging_level of
that schedule to logging_full
to catch all changes made to that table and view all operations in
dba_scheduler_job_log view
SQL> create table job_table1 (id number);
Table created.
SQL> BEGIN
sys.dbms_scheduler.create_job(
job_name => 'JOB1',
job_type => 'PLSQL_BLOCK',
job_action => 'INSERT INTO job_table1 values(1);',
repeat_interval => 'FREQ=MINUTELY',
start_date => sysdate,
enabled => true);
END;
/
PL/SQL procedure successfully completed.
SQL> select * from job_table1;
ID
----------
1
SQL> begin
DBMS_SCHEDULER.SET_ATTRIBUTE('JOB1','logging_level',DBMS_SCHEDULER.LOGGING_FULL);
end;
/
PL/SQL procedure successfully completed.
SQL> begin
2
DBMS_SCHEDULER.DISABLE('JOB1',TRUE);
3
end;
4
/
PL/SQL procedure successfully completed.
SQL> begin
2
DBMS_SCHEDULER.ENABLE('JOB1');
3
END;
4
/
PL/SQL procedure successfully completed.
SQL> drop table job_table1;
Table dropped.
Now we can query
dba_scheduler_job_log to see
the values:
select
log_id,
to_char(log_date,'dd/mm/yyyy hh24:mi:ss')
log_date,
substr(job_name, 1,20) job_name,
substr(status, 1,10) status,
additional_info
operation
from
dba_scheduler_job_log
where
job_name='JOB1'
order by
log_date ;
LOG_ID
LOG_DATE
JOB_NAME
STATUS
OPERATION
------ ----------
---------
----------
-----------
450
31/05/2009 17:27:58 JOB1
SUCCEEDED
455
31/05/2009 17:28:57 JOB1
SUCCEEDED
459
31/05/2009 17:29:49 JOB1
FORCE="TRUE", REASON="manually disabled"
463
31/05/2009 17:30:24 JOB1
REASON="manually enabled"
467
31/05/2009 17:30:57 JOB1
SUCCEEDED
472
31/05/2009 17:31:57 JOB1
SUCCEEDED
477
31/05/2009 17:32:57 JOB1
FAILED
As it seen above, first two minutes, our job ran successfully. After we
disabled the job, the information about it was logged in
operation column. Then we
enabled it, it also logged in
operation column. Later, it ran two times successfully.
At the end,
we dropped the table, thus our job
failed and was logged in the
dba_scheduler_job_log view
with failed status.