Wednesday, November 25, 2009

Query user session lock.

Many time I found there are many sessions still holding in database but they are not blocking another session, but I am not sure this is the right way to solve this problem. By use the below script to search and kill the session that not the user's work.

-- Query --
select b.username, spid, a.sid, b.serial#, ctime
from v$lock a, v$session b, v$process c
where a.sid = b.sid
and b.paddr = c.addr
and b.username not in ('SYS','SYSTEM');


-- Result --
USERNAME SPID SID SERIAL# CTIME
------------------------------ ------------ ---------- ---------- ----------
XXXCLIENT 25735 362 49353 55914
YYYCLIENT 19971 480 60967 0
YYYCLIENT 19971 480 60967 0
XXXUSER 13439 135 65198 55886
XXXCLIENT 25735 362 49353 55914
YYYCLIENT 20456 252 34722 55907

== TaTsHuYa ==

No comments: