My Session Wait Events Analysis (vmyev.sql)
What This Script Does
Section titled “What This Script Does”This script queries Oracle views to provide database information via the vmyev.sql script.
The Script
Section titled “The Script”rem vmyev.sqlremttitle 'Session Events'remcol 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'rembreak on report on eventcompute sum of total_waits total_timeouts time_waited on reportremselect 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;
What This Script Does
Section titled “What This Script Does”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.
Key Features
Section titled “Key Features”- 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.
Required Privileges
Section titled “Required Privileges”SELECT on V$SESSION_EVENTSELECT on V$SESSION
Sample Output
Section titled “Sample Output” 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.8SQL*Net message from client 145 1,234 2 0.2 456,789 370.2SQL*Net message to client 145 1,235 0 0.0 123 0.1buffer busy waits 145 45 3 6.7 234 5.2db file scattered read 145 123 0 0.0 1,456 11.8db file sequential read 145 678 0 0.0 3,456 5.1direct path read 145 34 0 0.0 123 3.6latch: cache buffers chains 145 15 0 0.0 67 4.5log file sync 145 89 0 0.0 445 5.0
======= ======= =========sum 3,465 5 462,738
Key Output Columns
Section titled “Key Output Columns”- 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)
Understanding Session Wait Events
Section titled “Understanding Session Wait Events”Network and Client Events
Section titled “Network and Client Events”SQL*Net Events
Section titled “SQL*Net Events”-- 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
Database I/O Events
Section titled “Database I/O Events”Read Operations
Section titled “Read Operations”-- 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 Operations
Section titled “Direct Path Operations”-- direct path read:-- Bypasses buffer cache (large sorts, parallel operations)-- Usually indicates parallel query or large operations-- Performance depends on storage subsystem speed
Concurrency and Locking Events
Section titled “Concurrency and Locking Events”Buffer and Latch Waits
Section titled “Buffer and Latch Waits”-- 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
Transaction Events
Section titled “Transaction Events”-- log file sync:-- Commit processing waits-- Average wait < 10ms: Good redo performance-- High waits: Redo log performance issues
Common Use Cases
Section titled “Common Use Cases”-
Session Performance Analysis
- Identify what the current session is waiting for
- Understand session-specific performance issues
- Optimize specific SQL operations
- Troubleshoot application performance
-
Development and Testing
- Analyze wait patterns during development
- Identify performance issues in new code
- Validate optimization efforts
- Understand application behavior
-
Troubleshooting Session Issues
- Diagnose slow-running operations
- Identify bottlenecks in session processing
- Correlate waits with specific activities
- Plan performance improvements
-
Application Optimization
- Understand application wait patterns
- Identify client-side vs database-side issues
- Optimize database interaction patterns
- Plan application architecture improvements
Analysis Techniques
Section titled “Analysis Techniques”Performance Assessment
Section titled “Performance Assessment”Identify Top Wait Events
Section titled “Identify Top Wait Events”-- 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)
Performance Baselines
Section titled “Performance Baselines”-- 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
Problem Identification
Section titled “Problem Identification”Client-Side Issues
Section titled “Client-Side Issues”-- High SQL*Net message from client indicates:-- Slow client processing-- Network latency-- Application design issues-- Client resource constraints
Database-Side Issues
Section titled “Database-Side Issues”-- High database wait events indicate:-- Storage performance problems-- Memory pressure-- Locking/contention issues-- SQL efficiency problems
Session Optimization Strategies
Section titled “Session Optimization Strategies”Network and Client Optimization
Section titled “Network and Client Optimization”Reduce Client Waits
Section titled “Reduce Client Waits”-- Strategies for high SQL*Net waits:-- Optimize client-side processing-- Reduce network round trips-- Use bulk operations-- Consider connection pooling
Application Design
Section titled “Application Design”-- Improve application efficiency:-- Batch database operations-- Use bind variables-- Optimize SQL statements-- Implement proper error handling
Database Operation Optimization
Section titled “Database Operation Optimization”I/O Optimization
Section titled “I/O Optimization”-- For high I/O waits:-- Optimize SQL statement performance-- Review index usage-- Consider partitioning-- Improve storage configuration
Concurrency Optimization
Section titled “Concurrency Optimization”-- For locking/latching waits:-- Optimize transaction design-- Reduce lock hold times-- Consider alternative approaches-- Review application timing
Advanced Analysis
Section titled “Advanced Analysis”Comparative Analysis
Section titled “Comparative Analysis”-- Compare wait patterns:-- Before and after code changes-- Different execution methods-- Various data volumes-- Different system loads
Wait Event Correlation
Section titled “Wait Event Correlation”-- Correlate waits with:-- Specific SQL statements-- Application operations-- System resource usage-- Time of day patterns
Session Monitoring Over Time
Section titled “Session Monitoring Over Time”-- Track session progression:-- Run script at intervals-- Monitor cumulative changes-- Identify performance trends-- Detect degradation points
Integration with Development
Section titled “Integration with Development”Code Optimization
Section titled “Code Optimization”SQL Statement Analysis
Section titled “SQL Statement Analysis”-- Use with SQL tuning:-- Run before SQL execution-- Execute problematic SQL-- Run vmyev.sql after execution-- Analyze wait pattern changes
Performance Testing
Section titled “Performance Testing”-- Include in performance tests:-- Baseline measurement-- Load testing with waits analysis-- Regression testing-- Optimization validation
Application Development
Section titled “Application Development”Development Workflow
Section titled “Development Workflow”-- Integrate into development:-- Run after each major operation-- Include in unit test analysis-- Document normal wait patterns-- Set performance expectations
Debugging Support
Section titled “Debugging Support”-- Use for debugging:-- Identify slow operations-- Correlate waits with code paths-- Validate optimization efforts-- Support root cause analysis
Best Practices
Section titled “Best Practices”Regular Monitoring
Section titled “Regular Monitoring”Development Phase
Section titled “Development Phase”-- During development:-- Monitor wait patterns regularly-- Document expected waits-- Identify optimization opportunities-- Establish performance baselines
Production Analysis
Section titled “Production Analysis”-- In production environments:-- Use for specific session troubleshooting-- Compare with normal patterns-- Identify unusual wait events-- Support performance investigations
Documentation and Analysis
Section titled “Documentation and Analysis”Performance Documentation
Section titled “Performance Documentation”-- Document findings:-- Normal wait patterns for operations-- Performance expectations-- Optimization opportunities-- Known issues and workarounds
Trend Analysis
Section titled “Trend Analysis”-- Track changes over time:-- Compare across application versions-- Monitor for performance regression-- Validate optimization efforts-- Plan future improvements
Troubleshooting Common Patterns
Section titled “Troubleshooting Common Patterns”High Network Waits
Section titled “High Network Waits”Symptoms
Section titled “Symptoms”- SQL*Net message from client > 50% of total wait time
- High average waits for SQL*Net events
- Low database-side wait events
Resolution
Section titled “Resolution”-- Address network issues:-- Optimize client application-- Reduce network round trips-- Check network infrastructure-- Consider connection optimization
High I/O Waits
Section titled “High I/O Waits”Symptoms
Section titled “Symptoms”- db file sequential/scattered read dominate waits
- High average wait times for I/O events
- Many I/O wait occurrences
Resolution
Section titled “Resolution”-- Optimize I/O performance:-- Review and tune SQL statements-- Check index usage and effectiveness-- Consider storage performance tuning-- Review table and index organization
Concurrency Issues
Section titled “Concurrency Issues”Symptoms
Section titled “Symptoms”- Buffer busy waits or latch waits present
- High timeout percentages
- Blocking-related wait events
Resolution
Section titled “Resolution”-- Address concurrency problems:-- Review application transaction design-- Consider timing and scheduling changes-- Optimize hot blocks access patterns-- Review locking strategies
Related Scripts
Section titled “Related Scripts”- vsessev.sql - Session-level wait event statistics
- vsessw.sql - Active session waits with parameters
- vsession.sql - Complete session information
- gvsessw.sql - RAC-aware session waits
Summary
Section titled “Summary”This script is essential for:
- Session-Level Performance Analysis - Understanding current session behavior
- Development and Testing - Optimizing code and validating performance
- Troubleshooting - Diagnosing specific session issues
- Application Optimization - Improving database interaction patterns
- Performance Baseline - Establishing normal wait patterns