Skip to content

My Session Wait Events Analysis (vmyev.sql)

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

rem vmyev.sql
rem
ttitle 'Session Events'
rem
col sid format 9999 heading 'SID'
col event format a28 heading 'EVENT'
col total_waits format 9999999 heading 'TOTAL|WAITS'
col total_timeouts format b999999 heading 'TOTAL|TIMEOUTS'
col timeout_pct format b999.9 heading 'TIME|OUT|PCT'
col time_waited format b999999999 heading 'TIME|WAITED'
col average_wait format b999999.9 heading 'AVERAGE|WAIT'
rem
break on report on event
compute sum of total_waits total_timeouts time_waited on report
rem
select e.event,
e.sid,
e.total_waits,
e.total_timeouts,
100 * e.total_timeouts / e.total_waits timeout_pct,
e.time_waited,
e.average_wait
from v$session_event e,
v$session s
where e.sid = s.sid
and s.audsid = userenv('sessionid')
order by e.event, e.sid;

This script provides a detailed analysis of wait events for the current user session, showing cumulative wait statistics since the session began. It’s invaluable for developers and DBAs to understand what their session is waiting for, identify performance bottlenecks, and optimize session-specific operations. The script automatically filters to show only the current session’s wait events.

  • Session-Specific Analysis: Shows wait events only for the current session
  • Comprehensive Metrics: Displays waits, timeouts, and timing information
  • Timeout Analysis: Calculates timeout percentages for each event
  • Performance Baseline: Provides cumulative statistics since session start
  • Self-Targeting: Automatically identifies current session using USERENV
  • Summary Totals: Provides overall session wait statistics
@vmyev.sql

No parameters required - automatically analyzes the current session.

SELECT on V$SESSION_EVENT
SELECT on V$SESSION
Session Events
EVENT SID TOTAL TOTAL TIME TIME AVERAGE
WAITS TIMEOUTS OUT WAITED WAIT
PCT
---------------------------- ---- ------- ------- ---- --------- -------
SQL*Net break/reset to client 145 12 0 0.0 45 3.8
SQL*Net message from client 145 1,234 2 0.2 456,789 370.2
SQL*Net message to client 145 1,235 0 0.0 123 0.1
buffer busy waits 145 45 3 6.7 234 5.2
db file scattered read 145 123 0 0.0 1,456 11.8
db file sequential read 145 678 0 0.0 3,456 5.1
direct path read 145 34 0 0.0 123 3.6
latch: cache buffers chains 145 15 0 0.0 67 4.5
log file sync 145 89 0 0.0 445 5.0
======= ======= =========
sum 3,465 5 462,738
  • EVENT: Name of the wait event
  • SID: Session ID (will be consistent for all rows - your session)
  • TOTAL WAITS: Cumulative number of waits for this event since session start
  • TOTAL TIMEOUTS: Number of waits that resulted in timeouts
  • TIME OUT PCT: Percentage of waits that timed out
  • TIME WAITED: Total time waited for this event (centiseconds)
  • AVERAGE WAIT: Average wait time per occurrence (centiseconds)
-- SQL*Net message from client:
-- High values: Client-side processing delays
-- Long average waits: Network latency or client issues
-- Indicates: Time waiting for client to send next request
-- SQL*Net message to client:
-- Usually very low average waits
-- High values may indicate network issues
-- Represents: Time sending data to client
-- db file sequential read:
-- Single block reads (index lookups, ROWID access)
-- Average wait < 10ms: Good storage performance
-- Average wait > 20ms: Storage performance issues
-- db file scattered read:
-- Multi-block reads (full table scans, index fast full scans)
-- Average wait < 50ms: Good for multi-block operations
-- High waits: Storage bottleneck or large I/O operations
-- direct path read:
-- Bypasses buffer cache (large sorts, parallel operations)
-- Usually indicates parallel query or large operations
-- Performance depends on storage subsystem speed
-- buffer busy waits:
-- Contention for specific blocks
-- High timeout %: Severe contention
-- May indicate hot blocks or poor design
-- latch: cache buffers chains:
-- Buffer cache access contention
-- High values: Memory or CPU pressure
-- May need buffer cache tuning
-- log file sync:
-- Commit processing waits
-- Average wait < 10ms: Good redo performance
-- High waits: Redo log performance issues
  1. Session Performance Analysis

    • Identify what the current session is waiting for
    • Understand session-specific performance issues
    • Optimize specific SQL operations
    • Troubleshoot application performance
  2. Development and Testing

    • Analyze wait patterns during development
    • Identify performance issues in new code
    • Validate optimization efforts
    • Understand application behavior
  3. Troubleshooting Session Issues

    • Diagnose slow-running operations
    • Identify bottlenecks in session processing
    • Correlate waits with specific activities
    • Plan performance improvements
  4. Application Optimization

    • Understand application wait patterns
    • Identify client-side vs database-side issues
    • Optimize database interaction patterns
    • Plan application architecture improvements
-- From the output, focus on events with:
-- 1. Highest TIME WAITED (total impact)
-- 2. Highest AVERAGE WAIT (per-occurrence impact)
-- 3. High TIMEOUT PCT (resource contention)
-- 4. Many TOTAL WAITS (frequency issues)
-- Establish baselines by running:
-- 1. At session start (after login)
-- 2. After specific operations
-- 3. At different times during session
-- 4. Before and after optimization changes
-- High SQL*Net message from client indicates:
-- Slow client processing
-- Network latency
-- Application design issues
-- Client resource constraints
-- High database wait events indicate:
-- Storage performance problems
-- Memory pressure
-- Locking/contention issues
-- SQL efficiency problems
-- Strategies for high SQL*Net waits:
-- Optimize client-side processing
-- Reduce network round trips
-- Use bulk operations
-- Consider connection pooling
-- Improve application efficiency:
-- Batch database operations
-- Use bind variables
-- Optimize SQL statements
-- Implement proper error handling
-- For high I/O waits:
-- Optimize SQL statement performance
-- Review index usage
-- Consider partitioning
-- Improve storage configuration
-- For locking/latching waits:
-- Optimize transaction design
-- Reduce lock hold times
-- Consider alternative approaches
-- Review application timing
-- Compare wait patterns:
-- Before and after code changes
-- Different execution methods
-- Various data volumes
-- Different system loads
-- Correlate waits with:
-- Specific SQL statements
-- Application operations
-- System resource usage
-- Time of day patterns
-- Track session progression:
-- Run script at intervals
-- Monitor cumulative changes
-- Identify performance trends
-- Detect degradation points
-- Use with SQL tuning:
-- Run before SQL execution
-- Execute problematic SQL
-- Run vmyev.sql after execution
-- Analyze wait pattern changes
-- Include in performance tests:
-- Baseline measurement
-- Load testing with waits analysis
-- Regression testing
-- Optimization validation
-- Integrate into development:
-- Run after each major operation
-- Include in unit test analysis
-- Document normal wait patterns
-- Set performance expectations
-- Use for debugging:
-- Identify slow operations
-- Correlate waits with code paths
-- Validate optimization efforts
-- Support root cause analysis
-- During development:
-- Monitor wait patterns regularly
-- Document expected waits
-- Identify optimization opportunities
-- Establish performance baselines
-- In production environments:
-- Use for specific session troubleshooting
-- Compare with normal patterns
-- Identify unusual wait events
-- Support performance investigations
-- Document findings:
-- Normal wait patterns for operations
-- Performance expectations
-- Optimization opportunities
-- Known issues and workarounds
-- Track changes over time:
-- Compare across application versions
-- Monitor for performance regression
-- Validate optimization efforts
-- Plan future improvements
  • SQL*Net message from client > 50% of total wait time
  • High average waits for SQL*Net events
  • Low database-side wait events
-- Address network issues:
-- Optimize client application
-- Reduce network round trips
-- Check network infrastructure
-- Consider connection optimization
  • db file sequential/scattered read dominate waits
  • High average wait times for I/O events
  • Many I/O wait occurrences
-- Optimize I/O performance:
-- Review and tune SQL statements
-- Check index usage and effectiveness
-- Consider storage performance tuning
-- Review table and index organization
  • Buffer busy waits or latch waits present
  • High timeout percentages
  • Blocking-related wait events
-- Address concurrency problems:
-- Review application transaction design
-- Consider timing and scheduling changes
-- Optimize hot blocks access patterns
-- Review locking strategies

This script is essential for:

  1. Session-Level Performance Analysis - Understanding current session behavior
  2. Development and Testing - Optimizing code and validating performance
  3. Troubleshooting - Diagnosing specific session issues
  4. Application Optimization - Improving database interaction patterns
  5. Performance Baseline - Establishing normal wait patterns