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

  1. rem
  2. rem $Header: blocking.sql,v 6002607.2 89/10/12 19:57:20 cyang Exp $ blocking.sql Copyr (c) 1989 Oracle
  3. rem
  4. /* This script creates a view called blocking_locks that can be queried
  5.  * to determine which locks are blocking the system.  It is mostly useful
  6.  * for finding processes that have died holding locks, and that for some
  7.  * reason have not been cleaned up by PMON.
  8.  *  
  9.  * It finds all the locks and latches that have processes waiting on them
  10.  * that are held by a process that is not waiting on another lock.  In
  11.  * other words it finds the locks that are at the top of the wait-for
  12.  * graph.
  13.  *  
  14.  * The blocking_locks view also gives information on the process that is
  15.  * holding the lock that is blocking the system.
  16.  *  
  17.  * Note that this view will not work if there is some sort of circular
  18.  * dependence between processes holding locks.  That is, it will not work
  19.  * in the case that there is a deadlock that is not detected automatically
  20.  * by the system.  Also, the results of the view are not dependable if there
  21.  * are a lot of lock transitions.  It is really only useful for the case when
  22.  * the system is wedged.
  23.  *  
  24.  * You must have access to the fixed tables (owned by sys) in order to
  25.  * use the blocking_locks view.
  26.  */
  27.  
  28. drop view ALL_LOCKS_VIEW;
  29.  
  30. /* All_locks_view has a row for each lock or latch that is being held, and 
  31.  * one row for each outstanding request for a lock or latch.
  32.  * The columns  of all_locks_view are:
  33.  *   type    - type of lock (DDL, LATCH, etc.)
  34.  *   lmode   - mode the lock is currently held in by process pid
  35.  *   pid     - oracle pid of process that this row describes
  36.  *   id1     - lock specific identifier of the lock
  37.  *   id2     - lock specific identifier of the lock
  38.  *   request - mode that the lock is being requested in by process pid
  39.  */
  40. create view ALL_LOCKS_VIEW as
  41.   select type, lmode, pid, to_char(id1) id1, to_char(id2) id2, request 
  42.       from v$lock                /* processes waiting on or holding enqueues */
  43.  union
  44.   select 'LATCH', 6, pid, rawtohex(laddr), ' ', 0   /* procs holding latches */
  45.       from v$latchholder                      /* 6 = exclusive, 0 = not held */
  46.  union
  47.   select 'LATCH', 0, pid, latchwait,' ',6          /* procs waiting on latch */
  48.       from v$process
  49.     where latchwait is not null;
  50.  
  51. /* drop old obsolete view */
  52. drop view BLOCKING_LOCKS1;
  53.  
  54. drop view BLOCKING_LOCKS;
  55.  
  56. /* Locks being requested by some process, that are held by processes 
  57.  * that are not waiting to acquire some other lock.  In other words 
  58.  * the locks  at the top of the WAIT-FOR tree.  Also some information
  59.  * about the holder of the lock.
  60.  */
  61.  
  62. create view BLOCKING_LOCKS as
  63. select h.type        lock_type,
  64.     decode( h.lmode, 
  65.         0, 'NONE',           /* Mon Lock equivalent */
  66.                 1, 'Null Mode',      /* N */
  67.         2, 'Row-S (SS)',     /* L */
  68.         3, 'Row-X (SX)',     /* R */
  69.         4, 'Share (S)',      /* S */
  70.         5, 'S/Row-X (SSX)',  /* C */
  71.         6, 'Exclusive (X)',  /* X */
  72.         h.lmode)
  73.             lock_mode,
  74.     h.pid        orcl_pid,                       /* oracle process id */
  75.     s.username    orcl_user,                       /* oracle user name */
  76.     p.spid         os_pid,                    /* OS specific process id */
  77.     p.username     os_user,                         /* OS specific name */
  78.     program,                             /* program that user is running */
  79.     terminal,                             /* terminal that user is using */
  80.     h.id1 rsrc_id1,    /* the value of these depends on the type of lock */
  81.     h.id2 rsrc_id2
  82.   from v$session s, v$process p, all_locks_view h, all_locks_view r
  83.  where  r.request  >  1     /* someone is waiting for (requesting) the lock  */
  84.   and   h.lmode    >  1                             /* h is holding the lock */
  85.   and   h.type     =  r.type
  86.   and   h.id1      =  r.id1
  87.   and   h.id2      =  r.id2
  88.   and   h.pid      =  p.pid
  89.   and   p.lockwait is null
  90.   and   p.latchwait is null
  91.   and   p.addr     =   s.paddr;
  92.  
  93.  
  94.