User Wait Time Analysis (waitID_group.sql)
What This Script Does
Section titled “What This Script Does”This script provides comprehensive user performance analysis by:
- Combining wait event times and CPU usage for complete user resource consumption
- Filtering to application users (those containing ‘USR’ in username)
- Excluding SQL*Net events to focus on database-internal waits
- Aggregating across all RAC instances for cluster-wide user analysis
- Ranking users by total resource consumption (wait time + CPU time)
Script
Section titled “Script”SELECT uname,sum(tws) FROM (select s.username uname, sum(e.time_waited_micro) / 1000000 tws from gv$session_event e, gv$session swhere s.sid -0 = e.sid and s.username like '%USR%' and s.inst_id = e.inst_idand e.event not like '%SQL*Net%'group by s.usernameUNION ALLselect ss.username uname, SUM(s.value) / 100 tws from gv$sesstat s, gv$statname n, gv$session ss where n.statistic# = s.statistic# and s.value <> 0 and s.sid = ss.sid and s.inst_id = ss.inst_id and ss.username like '%USR%' and N.NAME = 'CPU used by this session'GROUP BY ss.username)group by unameORDER BY 2 desc/SQL> @waitID_group.sqlRequired Privileges
Section titled “Required Privileges”- SELECT on GV$SESSION_EVENT
- SELECT on GV$SESSION
- SELECT on GV$SESSTAT
- SELECT on GV$STATNAME
Sample Output
Section titled “Sample Output”UNAME SUM(TWS)-------------------- ------------SALES_USR 12,345.67REPORTS_USR 8,901.23BATCH_USR 6,789.45WEBAPP_USR 4,567.89ETL_USR 3,456.78ANALYTICS_USR 2,345.67MOBILE_USR 1,234.56Key Output Columns
Section titled “Key Output Columns”- UNAME: Username containing ‘USR’ pattern
- SUM(TWS): Total time in seconds (wait time + CPU time) for the user across all sessions and instances
Understanding the Metrics
Section titled “Understanding the Metrics”Total Time Calculation
Section titled “Total Time Calculation”The script combines two key components:
- Wait Time: Time spent waiting for database events (I/O, locks, etc.)
- CPU Time: Actual CPU processing time used by sessions
Why Both Metrics Matter
Section titled “Why Both Metrics Matter”- Wait Time Only: Shows database bottlenecks but misses CPU-intensive operations
- CPU Time Only: Shows processing load but misses I/O and contention issues
- Combined: Provides complete picture of user resource consumption
Common Use Cases
Section titled “Common Use Cases”-
Resource Usage Analysis
- Identify users consuming most database resources
- Plan capacity based on user workload patterns
- Charge-back analysis for multi-tenant environments
-
Performance Troubleshooting
- Find users experiencing performance issues
- Prioritize optimization efforts by impact
- Identify application users vs system overhead
-
Workload Characterization
- Understand user behavior patterns
- Plan maintenance windows around user activity
- Size infrastructure for peak user loads
Performance Analysis
Section titled “Performance Analysis”Baseline Expectations
Section titled “Baseline Expectations”- Low Resource Users: < 100 seconds total time
- Moderate Users: 100-1000 seconds total time
- Heavy Users: > 1000 seconds total time
- Critical Users: > 3600 seconds (1 hour) total time
Workload Classification
Section titled “Workload Classification”Users can be classified by their resource consumption patterns:
- CPU-Intensive: High CPU time relative to wait time
- I/O-Intensive: High wait time from I/O events
- Mixed Workload: Balanced CPU and wait time
Advanced Analysis
Section titled “Advanced Analysis”User Performance Details
Section titled “User Performance Details”-- Get detailed breakdown for specific userSELECT s.username, e.event, COUNT(*) sessions, SUM(e.total_waits) total_waits, SUM(e.time_waited_micro)/1000000 total_wait_secs, ROUND(AVG(e.time_waited_micro/GREATEST(e.total_waits,1))/1000, 2) avg_wait_msFROM gv$session_event e, gv$session sWHERE s.sid = e.sidAND s.inst_id = e.inst_idAND s.username = 'SALES_USR'AND e.time_waited_micro > 0GROUP BY s.username, e.eventORDER BY total_wait_secs DESC;Session Distribution Analysis
Section titled “Session Distribution Analysis”-- Check session distribution across instancesSELECT inst_id, username, COUNT(*) session_countFROM gv$sessionWHERE username LIKE '%USR%'AND status = 'ACTIVE'GROUP BY inst_id, usernameORDER BY inst_id, session_count DESC;Monitoring and Optimization
Section titled “Monitoring and Optimization”Resource Threshold Monitoring
Section titled “Resource Threshold Monitoring”Set up alerts for users exceeding normal resource consumption:
- Warning: Users consuming > 30 minutes total time
- Critical: Users consuming > 1 hour total time
Performance Tuning Actions
Section titled “Performance Tuning Actions”- High CPU Users: Review SQL efficiency, consider better algorithms
- High Wait Users: Investigate I/O bottlenecks, locking issues
- Growing Usage: Plan for capacity expansion
Customization Options
Section titled “Customization Options”Username Pattern Modification
Section titled “Username Pattern Modification”-- Modify for different user patternsAND s.username LIKE 'APP_%' -- Application usersAND s.username NOT LIKE 'SYS%' -- Exclude system usersAND s.username IN ('USER1', 'USER2', 'USER3') -- Specific usersEvent Filtering
Section titled “Event Filtering”-- Include/exclude specific eventsAND e.event NOT LIKE '%idle%' -- Exclude idle eventsAND e.event IN ('db file sequential read', 'db file scattered read') -- I/O onlyIntegration with Application Monitoring
Section titled “Integration with Application Monitoring”Time-Based Analysis
Section titled “Time-Based Analysis”Track user activity patterns by time of day to:
- Identify peak usage periods
- Plan maintenance windows
- Size infrastructure for demand
Application Module Correlation
Section titled “Application Module Correlation”Combine with V$SESSION.MODULE to understand:
- Which applications drive resource usage
- Performance patterns by application component
- Connection pool efficiency
Best Practices
Section titled “Best Practices”-
Regular Monitoring
- Run during different time periods
- Compare business hours vs. off-hours
- Track trends over time
-
Threshold Management
- Establish user resource baselines
- Set appropriate alert thresholds
- Account for business cycle variations
-
Action Planning
- Prioritize optimization by total impact
- Focus on users with growing resource usage
- Plan capacity based on user growth patterns