Problem solve Get help with specific problems with your technologies, process and projects.

Identify the 'blockers' and the 'waiters'

This script will help you to determine what is holding a lock and what is waiting for it.

Do you want to know what are the blockers and what are the waiters? This SQL script was tested on 8i and 9i but was originally test on 7.3.4. It is very helpful in determining what is holding a lock and what is waiting for it.
set lin 132
set pages 66
column "SID"          format 999
column "SER"          format 99999
column "Table"        format A10
column "SPID"         format A5 
column "CPID"         format A5 
column "OS User"      format A7 
column "Table"        format A10
column "SQL Text"     format A40 wor
column "Mode"         format A20
column "Node"      format A10
column "Terminal"     format A8

spool /tmp/locks.lst

select
  s.sid "SID",
  s.serial# "SER",
  o.object_name "Table",
  s.osuser "OS User",
  s.machine "Node",
  s.terminal "Terminal",
  --p.spid "SPID",
  --s.process "CPID",
  decode (s.lockwait, null, 'Have Lock(s)', 'Waiting for <' || b.sid || '>') "Mode",
  substr (c.sql_text, 1, 150) "SQL Text"
from v$lock l,
  v$lock d,
  v$session s,
  v$session b,
  v$process p,
  v$transaction t,
  sys.dba_objects o,
  v$open_cursor c
where l.sid = s.sid
  and o.object_id (+) = l.id1
  and c.hash_value (+) = s.sql_hash_value
  and c.address (+) = s.sql_address
  and s.paddr = p.addr
  and d.kaddr (+) = s.lockwait
  and d.id2 = t.xidsqn (+)
  and b.taddr (+) = t.addr
  and l.type = 'TM'
group by
  o.object_name,
  s.osuser,
  s.machine,
  s.terminal,
  p.spid,
  s.process,
  s.sid,
  s.serial#,
  decode (s.lockwait, null, 'Have Lock(s)', 'Waiting for <' || b.sid || '>'),
  substr (c.sql_text, 1, 150)
order by 
  decode (s.lockwait, null, 'Have Lock(s)', 'Waiting for <' || b.sid || '>') desc,
  o.object_name asc,
  s.sid asc;
spool off;

This was last published in March 2004

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close