Killing Oracle Scheduling Sessions
Running jobs that were scheduled using the dbms_job package can be identified using the dba_jobs_running view.
The script listed below uses this view along with the v$session and v$process views to gather all information needed about the running jobs.
set feedback off
alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS';
set feedback on
select
jr.job,
s.username,
s.sid,
s.serial#,
p.spid,
s.lockwait,
s.logon_time
from
dba_jobs_running jr,
v$session s,
v$process p
where
jr.sid = s.sid
and
s.paddr = p.addr
order by
jr.job
;
JOB USERNAME SID SERIAL# SPID LOCKWAIT LOGON_TIME
----- --------- ------ ---------- ---- -------- --------------------
42 JOB_USER 235 3 3231 23-JUN-2004 08:21:25
99 JOB_USER 22 77 3199 23-JUN-2004 08:55:35
2 rows selected.
Running jobs that were scheduled using the dbms_scheduler package can be identified using the dba_scheduler_running_jobs view.
The jobs_running_10g.sql script listed below uses this view along with the v$session and v$process views to gather all information needed about the running jobs.
select
rj.job_name,
s.username,
s.sid,
s.serial#,
p.spid,
s.lockwait,
s.logon_time
from
dba_scheduler_running_jobs rj,
v$session s,
v$process p
where
rj.session_id = s.sid
and
s.paddr = p.addr
order by
rj.job_name
;
JOB_NAME USERNAME SID SERIAL# SPID LOCK LOGON_TIME
-------------------------- -------- --- ------- ---- ----- --------------------
TEST_FULL_JOB_DEFINITION SYS 22 125 3199 23-JUN-2004 09:22:12
1 row selected.
Regardless of the job scheduling mechanism, the important thing to note is that there are sid, serial#, and spid values associated with the running jobs. The sid and serial# values are necessary in order to kill the session, while the spid value is necessary if the associated operating system process or thread must be killed directly.
To kill the session from within Oracle, the sid and serial# values of the relevant session can then be substituted into the following statement:
alter system kill session 'sid,serial#';
With reference to the job listed above by the jobs_running_10g.sql script, the statement would look like this.
SQL> alter system kill session '22,125';
System altered.