home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / po7_win / db / rdbms71 / utllockt.sql < prev    next >
Text File  |  1994-08-07  |  4KB  |  122 lines

  1. rem 
  2. rem $Header: utllockt.sql 7001200.1 92/11/03 17:30:39 twang Generic<base> $ locktree.sql 
  3. rem 
  4. Rem Copyright (c) 1989 by Oracle Corporation
  5. Rem NAME
  6. REM    UTLLOCKT.SQL
  7. Rem  FUNCTION   - Print out the lock wait-for graph in tree structured fashion.
  8. Rem               This is useful for diagnosing systems that are hung on locks.
  9. Rem  NOTES
  10. Rem  MODIFIED
  11. Rem     glumpkin   10/20/92 -  Renamed from LOCKTREE.SQL 
  12. Rem     jloaiza    05/24/91 - update for v7 
  13. Rem     rlim       04/29/91 - change char to varchar2 
  14. Rem     Loaiza     11/01/89 - Creation
  15. Rem
  16.  
  17. /* Print out the lock wait-for graph in a tree structured fashion.
  18.  *  
  19.  * This script  prints  the  sessions in   the system  that  are waiting for
  20.  * locks,  and the locks that they  are waiting for.   The  printout is tree
  21.  * structured.  If a sessionid is printed immediately below and to the right
  22.  * of another session, then it is waiting for that session.  The session ids
  23.  * printed at the left hand side of the page are  the ones  that everyone is
  24.  * waiting for.
  25.  *  
  26.  * For example, in the following printout session 9 is waiting for
  27.  * session 8, 7 is waiting for 9, and 10 is waiting for 9.
  28.  *  
  29.  * WAITING_SESSION   TYPE MODE REQUESTED    MODE HELD         LOCK ID1 LOCK ID2
  30.  * ----------------- ---- ----------------- ----------------- -------- --------
  31.  * 8                 NONE None              None              0         0
  32.  *    9              TX   Share (S)         Exclusive (X)     65547     16
  33.  *       7           RW   Exclusive (X)     S/Row-X (SSX)     33554440  2
  34.  *       10          RW   Exclusive (X)     S/Row-X (SSX)     33554440  2
  35.  *  
  36.  * The lock information to the right of the session id describes the lock
  37.  * that the session is waiting for (not the lock it is holding).
  38.  *  
  39.  * Note that  this is a  script and not a  set  of view  definitions because
  40.  * connect-by is used in the implementation and therefore  a temporary table
  41.  * is created and dropped since you cannot do a join in a connect-by.
  42.  *  
  43.  * This script has two  small disadvantages.  One, a  table is created  when
  44.  * this  script is run.   To create  a table   a  number of   locks must  be
  45.  * acquired. This  might cause the session running  the script to get caught
  46.  * in the lock problem it is trying to diagnose.  Two, if a session waits on
  47.  * a lock held by more than one session (share lock) then the wait-for graph
  48.  * is no longer a tree  and the  conenct-by will show the session  (and  any
  49.  * sessions waiting on it) several times.
  50.  */
  51.  
  52.  
  53. /* Select all sids waiting for a lock, the lock they are waiting on, and the
  54.  * sid of the session that holds the lock.
  55.  *  UNION
  56.  * The sids of all session holding locks that someone is waiting on that
  57.  * are not themselves waiting for locks. These are included so that the roots
  58.  * of the wait for graph (the sessions holding things up) will be displayed.
  59.  */
  60. drop table lock_holders;
  61.  
  62. create table LOCK_HOLDERS   /* temporary table */
  63. (
  64.   waiting_session   number,
  65.   holding_session   number,
  66.   lock_type         varchar2(17),
  67.   mode_held         varchar2(10),
  68.   mode_requested    varchar2(10),
  69.   lock_id1          varchar2(10),
  70.   lock_id2          varchar2(10)
  71. );
  72.  
  73. drop   table dba_locks_temp;
  74. create table dba_locks_temp as select * from dba_locks;
  75.  
  76. /* This is essentially a copy of the dba_waiters view but runs faster since
  77.  *  it caches the result of selecting from dba_locks.
  78.  */
  79. insert into lock_holders 
  80.   select w.session_id,
  81.         h.session_id,
  82.         w.lock_type,
  83.         h.mode_held,
  84.         w.mode_requested,
  85.         w.lock_id1,
  86.         w.lock_id2
  87.   from dba_locks_temp w, dba_locks_temp h
  88.  where h.mode_held      !=  'None'
  89.   and  h.mode_held      !=  'Null'
  90.   and  w.mode_requested !=  'None'
  91.   and  w.lock_type       =  h.lock_type
  92.   and  w.lock_id1        =  h.lock_id1
  93.   and  w.lock_id2        =  h.lock_id2;
  94.  
  95. commit;
  96.  
  97. drop table dba_locks_temp;
  98.  
  99. insert into lock_holders 
  100.   select holding_session, null, 'None', null, null, null, null 
  101.     from lock_holders 
  102.  minus
  103.   select waiting_session, null, 'None', null, null, null, null
  104.     from lock_holders;
  105. commit;
  106.  
  107.  
  108. set charwidth 17;
  109.  
  110. /* Print out the result in a tree structured fashion */
  111. select  lpad(' ',3*(level-1)) || waiting_session waiting_session,
  112.     lock_type,
  113.     mode_requested,
  114.     mode_held,
  115.     lock_id1,
  116.     lock_id2
  117.  from lock_holders
  118. connect by  prior waiting_session = holding_session
  119.   start with holding_session is null;
  120.  
  121. drop table lock_holders;
  122.