Session I/O Statistics (vsessio.sql)
What This Script Does
Section titled “What This Script Does”This script provides session-level I/O performance analysis by:
- Displaying I/O statistics for each active session
- Calculating logical-to-physical read ratios for efficiency assessment
- Showing block modification activity per session
- Supporting filtering by OS user and database username
- Computing totals across all sessions for aggregate analysis
Script
Section titled “Script”rem vsessio.sqlremttitle 'Session I/O'remset linesize 100remcol sid format 9999 heading 'SID'col username format a12 heading 'USERNAME'col osuser format a10 heading 'OSUSER'col block_gets format b99999999 heading 'BLOCK|GETS'col consistent_gets format b999999999 heading 'CONSISTENT|GETS'col physical_reads format b9999999 heading 'PHYSICAL|READS'col block_changes format b99999999 heading 'BLOCK|CHANGES'col consistent_changes format b999999999 heading 'CONSISTENT|CHANGES'col hit_ratio format b9.000 heading 'HIT|RATIO'col log_phy format 9999 heading 'LOG/|PHY'rembreak on reportcompute sum - of block_gets consistent_gets physical_reads block_changes consistent_changes - on reportremselect i.sid, s.username, s.osuser, block_gets, consistent_gets, physical_reads, (block_gets + consistent_gets) / decode(physical_reads, 0, 1, physical_reads) log_phy, -- 1 - (physical_reads/decode(block_gets + consistent_gets, 0, 1, -- block_gets + consistent_gets)) hit_ratio, block_changes, consistent_changes from v$session s, v$sess_io i where i.sid = s.sid and (upper(s.osuser) like nvl(upper('&osuser'),'%') or s.osuser is null) and (s.username like nvl(upper('&username'),'%') or s.username is null) order by i.sid;
SQL> @vsessio.sqlEnter value for osuser: %Enter value for username: SCOTT
Parameters
Section titled “Parameters”- osuser: Operating system username pattern (% for all users)
- username: Database username pattern (% for all users, specific name for single user)
Required Privileges
Section titled “Required Privileges”- SELECT on V$SESSION
- SELECT on V$SESS_IO
Sample Output
Section titled “Sample Output”Session I/O
SID USERNAME OSUSER BLOCK CONSISTENT PHYSICAL LOG/ BLOCK CONSISTENT GETS GETS READS PHY CHANGES CHANGES----- ------------ ---------- ------- ---------- -------- ---- --------- ---------- 123 SCOTT jsmith 45,678 234,567 2,345 119 12,345 5,678 124 HR_USER mjohnson 23,456 156,789 1,234 146 8,901 3,456 125 SALES_APP appuser 78,901 345,678 4,567 93 23,456 12,345 126 BATCH_USER batchjob 234,567 1,234,567 12,345 119 45,678 23,456 127 REPORTS rptuser 12,345 89,012 891 114 2,345 1,234
------- ---------- -------- ---- --------- ----------sum 394,947 2,060,613 21,382 116 92,725 46,169
Key Output Columns
Section titled “Key Output Columns”Session Identification
Section titled “Session Identification”- SID: Session identifier
- USERNAME: Database username
- OSUSER: Operating system username
I/O Metrics
Section titled “I/O Metrics”- BLOCK GETS: Current mode block reads (for modifications)
- CONSISTENT GETS: Consistent mode block reads (for queries)
- PHYSICAL READS: Actual disk reads performed
- LOG/PHY: Logical to physical read ratio
- BLOCK CHANGES: Number of blocks modified
- CONSISTENT CHANGES: Consistent read changes (usually 0)
Understanding I/O Metrics
Section titled “Understanding I/O Metrics”Logical vs Physical I/O
Section titled “Logical vs Physical I/O”- Logical I/O: Memory buffer reads (block gets + consistent gets)
- Physical I/O: Actual disk reads when data not in buffer cache
- Higher LOG/PHY ratio: Better buffer cache efficiency
Block Access Types
Section titled “Block Access Types”- Block Gets: Reads for modification (current mode)
- Consistent Gets: Reads for queries (consistent mode)
- Block Changes: Actual modifications made to blocks
Performance Indicators
Section titled “Performance Indicators”- High Physical Reads: Potential I/O bottleneck or cache misses
- Low LOG/PHY Ratio: Poor buffer cache hit ratio
- High Block Changes: Heavy DML activity
Performance Analysis
Section titled “Performance Analysis”I/O Efficiency Assessment
Section titled “I/O Efficiency Assessment”-- Calculate buffer hit ratios by sessionSELECT sid, username, block_gets + consistent_gets logical_reads, physical_reads, ROUND((1 - physical_reads/GREATEST(block_gets + consistent_gets, 1)) * 100, 2) hit_ratio_pct, ROUND((block_gets + consistent_gets)/GREATEST(physical_reads, 1), 2) log_phy_ratioFROM v$session s, v$sess_io iWHERE s.sid = i.sidAND s.username IS NOT NULLAND (block_gets + consistent_gets) > 0ORDER BY logical_reads DESC;
High I/O Sessions
Section titled “High I/O Sessions”-- Identify sessions with highest I/O activitySELECT sid, username, osuser, (block_gets + consistent_gets) total_logical_io, physical_reads, block_changes, ROUND(physical_reads * 100 / GREATEST(block_gets + consistent_gets, 1), 2) miss_ratio_pctFROM v$session s, v$sess_io iWHERE s.sid = i.sidAND s.username IS NOT NULLORDER BY total_logical_io DESC;
Common Use Cases
Section titled “Common Use Cases”-
Session Performance Monitoring
- Identify high I/O consuming sessions
- Monitor buffer cache efficiency by user
- Track DML activity levels
-
Application Analysis
- Compare I/O patterns between applications
- Identify inefficient data access patterns
- Monitor batch job performance
-
Capacity Planning
- Understand I/O workload distribution
- Plan buffer cache sizing
- Identify peak I/O periods
Performance Tuning Insights
Section titled “Performance Tuning Insights”High Physical I/O Sessions
Section titled “High Physical I/O Sessions”For sessions with high physical reads:
- Review SQL Execution Plans: Check for full table scans
- Analyze Indexing: Ensure proper indexes exist
- Check Buffer Cache: May need larger buffer pool
Low Hit Ratios
Section titled “Low Hit Ratios”For sessions with poor buffer hit ratios:
- SQL Optimization: Review query efficiency
- Data Access Patterns: Check for sequential vs random access
- Application Design: Consider connection pooling or caching
High Block Changes
Section titled “High Block Changes”For sessions with extensive modifications:
- Batch Optimization: Consider bulk operations
- Transaction Sizing: Review commit frequency
- Indexing Impact: Monitor index maintenance overhead
Session I/O Monitoring
Section titled “Session I/O Monitoring”Real-time I/O Tracking
Section titled “Real-time I/O Tracking”-- Monitor I/O changes over timeCREATE TABLE session_io_history ( check_time DATE, sid NUMBER, username VARCHAR2(128), logical_reads NUMBER, physical_reads NUMBER, block_changes NUMBER);
-- Capture current snapshotINSERT INTO session_io_historySELECT SYSDATE, s.sid, s.username, i.block_gets + i.consistent_gets, i.physical_reads, i.block_changesFROM v$session s, v$sess_io iWHERE s.sid = i.sidAND s.username IS NOT NULL;
I/O Rate Analysis
Section titled “I/O Rate Analysis”-- Calculate I/O rates (requires historical data)SELECT sid, username, (current_logical - prev_logical) / ((current_time - prev_time) * 86400) logical_io_per_sec, (current_physical - prev_physical) / ((current_time - prev_time) * 86400) physical_io_per_secFROM session_io_trending_viewWHERE time_interval_minutes > 0;
Advanced Analysis
Section titled “Advanced Analysis”Application I/O Patterns
Section titled “Application I/O Patterns”-- Analyze I/O by application moduleSELECT s.module, COUNT(*) session_count, SUM(i.block_gets + i.consistent_gets) total_logical_io, SUM(i.physical_reads) total_physical_io, AVG(i.block_gets + i.consistent_gets) avg_logical_per_sessionFROM v$session s, v$sess_io iWHERE s.sid = i.sidAND s.username IS NOT NULLAND s.module IS NOT NULLGROUP BY s.moduleORDER BY total_logical_io DESC;
User I/O Summary
Section titled “User I/O Summary”-- Summarize I/O by database userSELECT username, COUNT(*) active_sessions, SUM(block_gets + consistent_gets) total_logical_reads, SUM(physical_reads) total_physical_reads, ROUND(AVG(block_gets + consistent_gets), 0) avg_logical_per_session, ROUND((1 - SUM(physical_reads)/GREATEST(SUM(block_gets + consistent_gets), 1)) * 100, 2) overall_hit_ratioFROM v$session s, v$sess_io iWHERE s.sid = i.sidAND s.username IS NOT NULLGROUP BY usernameORDER BY total_logical_reads DESC;
Buffer Cache Analysis
Section titled “Buffer Cache Analysis”Session Impact on Buffer Cache
Section titled “Session Impact on Buffer Cache”-- Estimate session impact on buffer cacheSELECT sid, username, ROUND((block_gets + consistent_gets) * 8192 / 1024 / 1024, 2) data_touched_mb, ROUND(physical_reads * 8192 / 1024 / 1024, 2) data_read_from_disk_mb, ROUND((1 - physical_reads/GREATEST(block_gets + consistent_gets, 1)) * 100, 2) personal_hit_ratioFROM v$session s, v$sess_io iWHERE s.sid = i.sidAND s.username IS NOT NULLAND (block_gets + consistent_gets) > 0ORDER BY data_touched_mb DESC;
Troubleshooting Performance Issues
Section titled “Troubleshooting Performance Issues”Identify Problematic Sessions
Section titled “Identify Problematic Sessions”- High Physical I/O: Sessions causing cache misses
- Low Hit Ratios: Inefficient data access patterns
- High Block Changes: Heavy DML impacting performance
Investigation Steps
Section titled “Investigation Steps”- Review Current SQL: Check V$SQL for active statements
- Analyze Execution Plans: Look for inefficient access paths
- Check Object Statistics: Verify optimizer statistics currency
Best Practices
Section titled “Best Practices”-
Regular Monitoring
- Check during peak business hours
- Compare patterns across different time periods
- Track trends for capacity planning
-
Performance Baselines
- Establish normal I/O patterns by application
- Document expected hit ratios for different workloads
- Monitor for deviations from baseline
-
Optimization Priorities
- Focus on highest I/O consuming sessions first
- Address low hit ratios through SQL tuning
- Consider infrastructure improvements for high I/O loads