Thursday, December 30, 2010

How to Kill Oracle Session

how to Kill Oracle Session
=============================

sometime one oracle session can make you tension.
for this you have to kill that session immediately.
but how ?
what is best way to kill a session ?
when which way you choose ?


First way :-
=============


via SQL* PLUS utility:

In order to use SQL*PLUS Approach, first we need to find out the SID, SERIAL# of the Session
which we want to kill. The following command to find the session and kill the session .

SQL> select username,sid,serial#,terminal from v$session;


SQL> alter system kill session ‘SID, SERIAL#’;


[note :
When we issue the above statement, It terminates a session, rolls back ongoing transactions,
releases all session locks, frees all session resources.
If the session is performing some activity that must be completed
(e.g. waiting for a reply from a remote database or rolling back a transaction),
Oracle waits for this activity to complete, kills the session then returns control.
If the wait lasts for 60 seconds then Oracle marks the session to be killed,
and returns control with a message that the session is marked to be killed.
It then gets killed when the activity is complete.
]

This is the best way. and Oracle recommended way.


Second way :-
=============



via KILL Command (for Unix/Linux)

To kill the sessions using KILL Command, we need to find out the SPID ( Server Process ID)
of the Oracle Session.

To find out a spid of a specific session

SQL> SELECT s.sid,p.spid, s.osuser, s.programFROM
v$process p, v$session s
WHERE p.addr = s.paddr
and s.sid=<:your_given_sid>;


Then issue the KILL Command


$ kill -9 SPID




[Note: Do not kill the sessions at the OS level (as per as possible).
This is not Oracle Recommendation way ]


Third way :-
=============


via ORAKILL Command (in Windows command prompt)

To kill the sessions using ORAKILL Command ( Windows), we need to find out the SPID of Session
and ORACLE_SID of your Oracle Database. Then issue ORAKILL Command

To find out a spid of a specific session


SQL> SELECT s.sid,p.spid, s.osuser, s.programFROM
v$process p, v$session s
WHERE p.addr = s.paddr
and s.sid=<:your_given_sid>;


Then issue the orakill Command



C:\> orakill ORACLE_SID SPID




[Note: Do not kill the sessions at the OS level (as per as possible).
This is not Oracle Recommendation way ]

No comments: