Monday, April 2, 2007

orakill on windows

This utility is provided only with Oracle databases on WINDOWS platforms.Ths executable allows a DBA to kill sessions in Oracle withuot connecting to the database.That is you can do it on DOS command prompt.(orakill.exe)

Unix system are processes based while windows environment are thread based.
In Unix, every oracle sessions can be seen individually by using the ps comand but in windows
based system all sessions are in the oracle.exe executables.That means you won't be able to see
sessions individually.

The orakill will do the same thing in windows what kill -9 does in UNIX.
C:\oracle>orakill
Usage: orakill sid thread
where sid = the Oracle instance to target
thread = the thread id of the thread to kill

The thread id should be retrieved from the spid column of a query such as:

select spid, osuser, s.program
from v$process p, v$session s
where p.addr=s.paddr;

to get a better view, you can user the below query to replace the above.

select b.spid, a.osuser, a.username
from v$process b, v$session a
where b.addr=a.paddr
and a.username is not null;
e.g
SPID OSUSER USERNAME
------------ ------------------------------ -------------------
2508 MURALI\innotiive PRASANA
2644 MURALI\innotiive ALI

C:\oracle>orakill PROD 2644
Kill of thread id 2644 in instance PROD successfully signalled.

SQL>select b.spid, a.osuser, a.username from
v$process b, v$session a where b.addr=a.paddr
and a.username is not null;
SPID OSUSER USERNAME
------------ ------------------------------ --------------
2508 MURALI\innotiive PRASANA

You can also kill a user session from the Oracle databasee.g.alter system kil session (sid,serial#);

You can get the value of sid and serial# from the v$session view.
One of the reason to use orakill instead of alter system kill session is orakill will clear
any locks that exist but alter system kill session will remain connected until it times out and
then it release the locks.

The orakill utility should be used as a last resort only. If the session cannot be killed more
gracefully (via alter system kill session), or the instance is inaccessible via SQL, then
orakill should be used to terminate the offending session.

Be careful not to kill a background process as this may cause the database to be down.

2 comments:

Sandeep said...

Hi,

Good article, just adding more information.

To kill session in Unix OS use the following command.

$> kill -9 "spid"

How to find spid see below.

select S.SID,S.SERIAL#,S.STATUS,S.USERNAME,
S.program, P.SPID,
MACHINE, S.osuser
FROM V$SESSION S, V$PROCESS P
and S.username is not null
AND S.PADDR = P.ADDR;

Anonymous said...

Well written article.