Skip to content

Session Enqueue Wait Analysis (vsessenq.sql)

This script queries Oracle views to provide database information via the vsessenq.sql script.

rem vsessenq.sql
rem
set linesize 132
rem
ttitle 'Session Waits - Enqueues'
rem
col event format a29 heading 'EVENT'
col sid format 9999 heading 'SID'
col seq# format 99999 heading 'SEQ'
col wait_time format b999 heading 'WAIT|TIME'
col seconds_in_wait format b999999 heading 'SECONDS|IN WAIT'
col state format a17 heading 'STATE'
col parm1 format a20 heading 'PARM1'
col parm2 format a20 heading 'PARM2'
col parm3 format a20 heading 'PARM3'
col parameters format a59 heading 'PARAMETERS'
rem
select w.sid,
seq#,
wait_time,
/*
select event,
seconds_in_wait,
state,
p1text, p1, p1raw,
p2text, p2, p2raw,
p3text, p3, p3raw
p1text || ' = ' || p1 parm1,
p2text || ' = ' || p2 parm2,
p3text || ' = ' || p3 parm3
*/
decode( p1text, null, null,
p1text || ' = ' || p1 ) ||
decode( p2text, null, null,
', ' || p2text || ' = ' || p2 ) ||
decode( p3text, null, null,
', ' || p3text || ' = ' || p3 )
parameters,
row_wait_obj#,
row_wait_file#,
row_wait_block#,
row_wait_row#
from v$session s,
v$session_wait w
where w.sid = s.sid
and w.event = 'enqueue'
order by event, p1, p2, p3;
rem
set linesize 80

The vsessenq.sql script monitors and analyzes session-level enqueue waits in Oracle databases. It identifies sessions that are currently waiting on enqueue locks, providing detailed information about the specific lock type, parameters, and row-level wait information. This is crucial for diagnosing blocking and deadlock scenarios.

SQL> @vsessenq.sql

No parameters required - The script automatically identifies all sessions currently waiting on enqueue events.

  • SELECT privilege on V$SESSION and V$SESSION_WAIT (usually requires DBA role or specific grants)
Session Waits - Enqueues
SID SEQ WAIT PARAMETERS ROW_WAIT_OBJ# ROW_WAIT_FILE# ROW_WAIT_BLOCK# ROW_WAIT_ROW#
----- ----- ---- --------------------------------------------------------- ------------- -------------- --------------- -------------
156 423 0 name|mode = 1415053318, id1 = 65537, id2 = 25 75234 4 12845 0
234 156 0 name|mode = 1415053318, id1 = 65537, id2 = 25 75234 4 12845 0
445 789 0 name|mode = 1414812756, id1 = 131073, id2 = 0 102456 5 23451 2
  • SID: Session ID experiencing the enqueue wait
  • SEQ: Sequence number of the wait event
  • WAIT TIME: Time since the wait began (0 = currently waiting)
  • PARAMETERS: Decoded enqueue parameters showing lock type and identifiers
  • ROW_WAIT_OBJ#: Object ID of the object being waited on
  • ROW_WAIT_FILE#: File number containing the waited-on row
  • ROW_WAIT_BLOCK#: Block number containing the waited-on row
  • ROW_WAIT_ROW#: Specific row number being waited on

The name|mode parameter encodes the enqueue type and mode:

  • TX (Transaction Lock): Row-level locking conflicts
  • TM (Table Lock): Table-level locking issues
  • DX (Distributed Transaction): Distributed transaction locks
  • UL (User Lock): Application-defined locks
  • id1/id2: Additional identifiers specific to the enqueue type
    • For TX locks: usually USN and slot numbers
    • For TM locks: object ID and table lock mode
    • For other locks: varies by lock type
  1. Blocking Session Analysis

    • Identify sessions waiting for locks held by other sessions
    • Determine the scope and impact of blocking scenarios
  2. Deadlock Investigation

    • Analyze enqueue waits that may lead to deadlock situations
    • Identify circular wait dependencies
  3. Row-Level Lock Monitoring

    • Monitor specific row-level locking conflicts
    • Identify hot blocks or rows causing contention
  4. Application Troubleshooting

    • Diagnose application-level locking issues
    • Identify poorly designed transaction patterns
  • wait_time = 0: Session is currently waiting
  • wait_time > 0: Time since the wait completed (historical)
  • Non-zero row_wait values: Specific row-level waits
  • Zero values: Table or object-level waits
  1. Identify Blocking Sessions:

    SELECT blocking_session, sid, seconds_in_wait
    FROM v$session
    WHERE blocking_session IS NOT NULL;
  2. Check Lock Holdings:

    SELECT * FROM v$lock
    WHERE sid IN (blocking_session_list);
  • TX Locks: Often indicate row-level blocking or deadlocks
  • TM Locks: Usually table-level operations conflicts
  • Long-running waits: May indicate hung transactions
  • Real-time Monitoring: Shows current enqueue waits as they occur
  • Detailed Parameters: Decodes enqueue parameters for easy interpretation
  • Row-level Details: Provides specific row wait information
  • Formatted Output: Clean, readable display of complex wait information
  • Only shows sessions currently waiting on enqueue events
  • Historical wait information is limited
  • Does not show the blocking sessions (use additional queries for complete analysis)
  1. Regular Monitoring: Run during peak hours to identify recurring issues
  2. Combine with Other Views: Use with V$LOCK and V$SESSION for complete analysis
  3. Document Patterns: Track common enqueue types for your application
  4. Proactive Resolution: Address long-running enqueue waits promptly to prevent cascading issues