Friday, October 26, 2007

How to unlock a record on Oracle

A life saver if you are working on Oracle and multithreading applications.


In AquaDataStudio run the following query to get the session_id and serial

Where the and are those of the locking process. Here is a script that will give you the locking information:

  select owner||'.'||object_name obj
,oracle_username||' ('||s.status||')' oruser
,os_user_name osuser
,machine computer
,l.process unix
,'||s.sid||','||s.serial#||' ss
,r.name rs
,to_char(s.logon_time,'yyyy/mm/dd hh24:mi:ss') time
from v$locked_object l
,dba_objects o
,v$session s
,v$transaction t
,v$rollname r
where l.object_id = o.object_id
and s.sid=l.session_id
and s.taddr=t.addr
and t.xidusn=r.usn

order by osuser, ss, obj

The DBA command to release the lock is:

For example the Db name is adem export ORACLE_SID=adem sqlplus /nolog connect /as sysdba ALTER SYSTEM KILL SESSION ',';

2 comments:

jon077 said...

The code snippet was really helpful... but I changed the ss col to:

s.sid||','||s.serial# ss ,



Then ran:
Alter System Kill Session '*value from ss above*'

Anonymous said...

Thanks for sharing...
___________________
Julie
The only Satellite Television

Delivers the Best Value in Entertainment