Find if a job is running
                                                 Last update (2012-06-16 19:47:38)
                                                                                                                   Date added (2008-02-09 16:09:19)

Summary
Here are the sql scipts for creating a job, running the job manual, enabling and disabling job and of course find if job is currently running.

How to
Create a job
This script creates a job, which runs a procedure (SYS.CHECK_ADAPTERS) every 30 minutes. The job is 185
BEGIN
SYS.DBMS_JOB.CHANGE
(
job => 185
,what => 'SYS.CHECK_ADAPTERS;'
,next_date => TO_DATE('11/02/2008 17:08:16','dd/mm/yyyy hh24:mi:ss')
,INTERVAL => 'SYSDATE+30/1440 '
);
END;
COMMIT;
Run the job manually
BEGIN
DBMS_JOB.RUN(job=>185);
END;
COMMIT;
/
Make the job broken
BEGIN
DBMS_JOB.BROKEN(job=>185,broken=>TRUE);
END;
COMMIT;
/
Place the job back online
BEGIN
DBMS_JOB.BROKEN(job=>185,broken=>FALSE);
END;
COMMIT;
/
Remove the job
BEGIN
DBMS_JOB.REMOVE(job=>185);
END;
COMMIT;
/
They all need and COMMIT;

Monitor if a job is running right now. It runs only with the RULE hint!
SELECT /*+ RULE */ D.JOB, V.SID, V.SERIAL#, STATUS, LOG_USER USERNAME, WHAT,
DECODE(TRUNC(SYSDATE - LOGON_TIME), 0, NULL,
TRUNC(SYSDATE - LOGON_TIME) || ' Days' || ' + ') ||
TO_CHAR(TO_DATE(TRUNC(MOD(SYSDATE-LOGON_TIME,1) * 86400), 'SSSSS'), 'HH24:MI:SS') RUNNING,
D.FAILURES, 'alter system kill session ' || '''' || V.SID || ', ' || V.SERIAL# || '''' || ' immediate;' KILL_SQL
FROM DBA_JOBS_RUNNING D, V$SESSION V, DBA_JOBS J
WHERE V.SID = D.SID
AND D.JOB = J.JOB;
To check running jobs on oracle RAC you can use query:
SELECT J.JOB, V.SID, S.SERIAL#, S.STATUS, LOWNER USERNAME, WHAT, 
DECODE(TRUNC(SYSDATE - LOGON_TIME), 0, NULL,
TRUNC(SYSDATE - LOGON_TIME) || ' Days' || ' + ') ||
TO_CHAR(TO_DATE(TRUNC(MOD(SYSDATE-LOGON_TIME,1) * 86400), 'SSSSS'), 'HH24:MI:SS') RUNNING, 
J.FAILURES, V.INST_ID INSTANCE, 
'alter system kill session ' || '''' || S.SID || ', ' || S.SERIAL# || '''' || ' immediate;' KILL_SQL
  FROM SYS.JOB$ J, GV$LOCK V, GV$SESSION S
  WHERE V.TYPE = 'JQ' 
  AND J.JOB = V.ID2 
  AND S.SID = V.SID
  AND AUDSID = 0;
Other links
How to kill a running job
Reviews
Categories
Oracle DBA-> (147)
  Alertlog (3)
  Archivelog (5)
  Auditing (1)
  Backup - Recovery (19)
  Database files (6)
  Database options (2)
  DB links (2)
  Dependencies (1)
  Dictionary (2)
  Exp-Imp Datapump (6)
  Jobs (2)
  Mview (2)
  Networking (3)
  Objects (7)
  Parameters (2)
  Redologs (6)
  Roles - Grants (2)
  Rollback - Undo (8)
  Segments (3)
  Sequences (2)
  Sessions (14)
  SGA (14)
  Tables (10)
  Tablespaces (10)
  Temp (4)
  Toad (5)
  Transactions (1)
  Upgrade (2)
  Users (3)
Oracle APPS DBA-> (66)
Exadata (1)
Performance Tuning-> (59)
Oracle Real Cases (24)
Oracle Errors (23)
Oracle SQL tricks (32)
Oracle RAC (3)
Oracle Security (8)
Filters
Search