Latch, mutex and beyond


     This file is part of demos for "Contemporary Latch Internals" seminar v.18.09.2010
     Copyright:   (c) Andrey S. Nikolaev ( RDTEX

       sqlplus/nolog @trace_latch_wait <latch#>

     Trace syscalls during wait for parent latch identified by latch#.

     This script intentionally use old-fashioned SQL to work with Oracle 8i
     shared_latches table can be downloaded from:
connect / as sysdba
set echo on
set define %
set verify off
alter session set max_dump_file_size=0;

/* determine a function to acquire the latch */
var db_v varchar2(100);
var db_comp varchar2(100);
begin dbms_utility.db_version(:db_v,:db_comp); end;

col latch_function new_value latch_function
col addr new_value laddr
col lname new_value lname
select decode(shared,'Y'
        ,decode(sign(replace(:db_v,'.','')-110000),1,'kslgetsl_w', 'kslgetsl')
        ,'kslgetl') latch_function,
      translate(,' /$''','____') lname
from v$latch_parent a1,shared_latches a2
  where (+)
  and a1.latch# = a2.latch# (+)
  and a1.latch#=%1
  and nvl(version,:db_v) = :db_v;

/* determine spid of current shadow process */
col spid new_value spid
 FROM v$process
 WHERE addr IN (SELECT paddr
  FROM v$session WHERE SID =  (SELECT SID FROM v$mystat WHERE ROWNUM = 1));

/* prepare script to acquire the latch for 3 sec 
   if latch is shared, get it in S mode 
set echo off
set head off
spool get_latch_to_trace.sql
select 'connect / as sysdba'||chr(10)||'oradebug setmypid'||chr(10)||
      'oradebug call '||'%latch_function'||
         ' 0x'||'%laddr'||' 1 2 3 8'||chr(10)||
      'host sleep 3'||chr(10)||
      'oradebug call kslfre 0x'||'%laddr'||chr(10)||
 from dual;

spool off
host sqlplus /nolog @get_latch_to_trace.sql &

oradebug setmypid
/* trace system calls for latch wait. Uncomment line corresponding to your OS */
/* Solaris: */
host truss -o%lname..lst  -p %spid &

/* Linux: */
/* host strace -o%lname..lst  -p %spid & */
/* HP-UX: */
/* host tusc -o%lname..lst  -p %spid & */

host sleep 1

/* Acquire the latch. If latch is shared get it in X mode */

oradebug call %latch_function 0x%laddr 1 2 3 16
oradebug call kslfre 0x%laddr



  1. […] instance crashes. I had to acquire such latches only for seconds. To achieve this, I wrote script latch_wait_trace.sql. The script uses latch number as an argument and spawns sqlplus to acquire corresponding parent […]

    Pingback by Hidden latch wait revolution that we missed « Latch, mutex and beyond — December 16, 2010 @ 8:26 pm | Reply

  2. […] from two sessions. My tool will be latch_spin_trace.sql. This script differs from previously used latch_wait_trace.sql by timeout values. In addition, it spawns spin.d DTrace script instead of truss. Through this post, […]

    Pingback by Spin tales: Part 1. Exclusive latches in Oracle 9.2-11g « Latch, mutex and beyond — January 6, 2011 @ 9:59 pm | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: