home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a524 / 28.ddi / admin / locktree.sql < prev    next >
Encoding:
Text File  |  1991-03-04  |  5.0 KB  |  122 lines

  1. rem
  2. rem $Header: locktree.sql,v 6002700.1 89/10/12 19:55:18 cyang Exp $ locktree.sql Copyr (c) 1989 Oracle
  3. rem
  4.  
  5. rem Print out the lock wait-for graph in a tree structured fashion.
  6. rem   
  7. rem  This script prints  the  processes in   the system  that  are waiting for
  8. rem  locks,  and the locks that they  are waiting for.   The  printout is tree
  9. rem  structured.  If a processid is printed immediately below and to the right
  10. rem  of another process, then it is waiting for that process.  The process ids
  11. rem  printed at the left hand side of the page are  the ones  that everyone is
  12. rem  waiting for.
  13. rem   
  14. rem  For example, in the following printout process 9 is waiting for
  15. rem  process 8, 7 is waiting for 9, and 10 is waiting for 9.
  16. rem   
  17. rem  PROCESS WAITING   TYPE MODE REQUESTED    MODE HELD         LOCK ID1 LOCK ID2
  18. rem  ----------------- ---- ----------------- ----------------- -------- --------
  19. rem  8                 NONE None              None              0         0
  20. rem     9              TX   Share (S)         Exclusive (X)     65547     16
  21. rem        7           RW   Exclusive (X)     S/Row-X (SSX)     33554440  2
  22. rem        10          RW   Exclusive (X)     S/Row-X (SSX)     33554440  2
  23. rem   
  24. rem  The lock information to the right of the process id describes the lock
  25. rem  that the process is waiting for (not the lock it is holding).
  26. rem   
  27. rem  You must have the blocking.sql script loaded for this  script to work (it
  28. rem  is in world$:blocking.sql).
  29. rem   
  30. rem  Note that  this is a  script and not a  set  of view  definitions because
  31. rem  connect-by is used in the implementation and therefore  a temporary table
  32. rem  is created and dropped since you cannot do a join in a connect-by.
  33. rem   
  34. rem  This script has two  small disadvantages.  One, a  table is created  when
  35. rem  this  script is run.   To create  a table   a  number of   locks must  be
  36. rem  acquired. This  might cause the process running  the script to get caught
  37. rem  in the lock problem it is trying to diagnose.  Two, if a process waits on
  38. rem  a lock held by more than one process (share lock) then the wait-for graph
  39. rem  is no longer a tree  and the  conenct-by will show the process  (and  any
  40. rem  processes waiting on it) several times.
  41. rem 
  42.  
  43. rem Select all pids waiting for a lock, the lock they are waiting on, and the
  44. rem  pid of the process that holds the lock.
  45. rem   UNION
  46. rem  The pids of all processes holding locks that someone is waiting on that
  47. rem  are not themselves waiting for locks. These are included so that the roots
  48. rem  of the wait for graph (the processes holding things up) will be displayed.
  49. rem   
  50. rem     pid    - pid of requesting process
  51. rem     type   - type of lock being requested
  52. rem     id1    - id1 of lock being requested (value is lock type specific)
  53. rem     id2    - id2 of lock being requested (value is lock type specific)
  54. rem     req    - mode lock is being requested in
  55. rem     hpid   - pid of process holding the lock
  56. rem     hmod   - mode the lock is held in
  57. rem 
  58. rem  NOTE:  For interpratation of id1 and id2 please refer to notes$:ksq.doc
  59. rem
  60. create table LOCK_HOLDERS 
  61. (
  62.   pid number(18),
  63.   type char(4),
  64.   id1 char(10),
  65.   id2 char(10),
  66.   req number,
  67.   hpid number,
  68.   hmod number
  69. );
  70.  
  71. insert into lock_holders 
  72. select r.pid, r.type, r.id1, r.id2, r.request req, h.pid hpid, h.lmode hmod
  73.   from all_locks_view h, all_locks_view r
  74.  where  r.request  >  1            /* R is waiting for (requesting) the lock */
  75.   and   h.lmode    >  1                             /* H is holding the lock */
  76.   and   h.type     =  r.type        /* H is holding the lock R is requesting */
  77.   and   h.id1      =  r.id1
  78.   and   h.id2      =  r.id2
  79. union
  80. select unique
  81.        h.pid, 'NONE', '0', '0', 0, -1, 0
  82.   from v$process p, all_locks_view h, all_locks_view r
  83.  where  r.request  >  1            /* R is waiting for (requesting) the lock */
  84.   and   h.lmode    >  1                             /* h is holding the lock */
  85.   and   h.type     =  r.type        /* H is holding the lock R is requesting */
  86.   and   h.id1      =  r.id1
  87.   and   h.id2      =  r.id2
  88.   and   h.pid      =  p.pid                                /* H is process P */
  89.   and   p.lockwait is null                    /* P is not waiting for a lock */
  90.   and   p.latchwait is null;
  91.  
  92. set charwidth 17;
  93.  
  94. rem Print out the result in a tree structured fashion
  95.  
  96. select lpad(' ',3*(level-1)) || pid "PROCESS WAITING",
  97.        type type, 
  98.        decode( req, 
  99.         0, 'None',           /* Mon Lock equivalent */
  100.                 1, 'Null Mode',      /* N */
  101.         2, 'Row-S (SS)',     /* L */
  102.         3, 'Row-X (SX)',     /* R */
  103.         4, 'Share (S)',      /* S */
  104.         5, 'S/Row-X (SSX)',  /* C */
  105.         6, 'Exclusive (X)',  /* X */
  106.         req) "MODE REQUESTED",
  107.        decode( hmod, 
  108.         0, 'None',           /* Mon Lock equivalent */
  109.                 1, 'Null Mode',      /* N */
  110.         2, 'Row-S (SS)',     /* L */
  111.         3, 'Row-X (SX)',     /* R */
  112.         4, 'Share (S)',      /* S */
  113.         5, 'S/Row-X (SSX)',  /* C */
  114.         6, 'Exclusive (X)',  /* X */
  115.         hmod) "MODE HELD",
  116.        id1 "LOCK ID1", id2 "LOCK ID2"
  117.  from lock_holders
  118. connect by  prior pid = hpid
  119.   start with hpid = -1;
  120.  
  121. drop table lock_holders;
  122.