Friday, July 31, 2009

Query to find locked objects in oracle

The following query will find the objects which have been locked by the user.
The query will return session id which can be used to alter the session which can release the lock.

SELECT SESS.OSUSER,
OBJ.OBJECT_NAME, SESS.SID,
sess.SERIAL#,SESS.USERNAME, SESS.MACHINE, SESS.TERMINAL, SESS.PROGRAM FROM V$LOCKED_OBJECT LO,V$SESSION SESS,DBA_OBJECTS OBJ WHERE LO.SESSION_ID=SESS.SID AND LO.OBJECT_ID=OBJ.OBJECT_ID

Then the session can be killed by the following alter command

ALTER SYSTEM KILL SESSION ‘sid, serial#’

Sid and serial# should be taken from the above query to find the locked objects

No comments:

Powered By Blogger