Buffer Busy Waits Analysis (vwait.sql)
What This Script Does
Section titled “What This Script Does”This script analyzes Oracle buffer busy wait statistics by examining different wait classes. Buffer busy waits occur when sessions cannot access database blocks because they are being used by other sessions for reads, writes, or other operations. This helps identify specific types of buffer contention.
Script
Section titled “Script”rem vwait.sqlremttitle 'Buffer Busy Waits'remcol class format a18 heading 'CLASS'col count format b999999999 heading 'COUNT'col time format b999999999 heading 'TIME'rembreak on reportcompute sum of count time on reportremselect class, count, time from v$waitstat order by class;
-- Run the script in SQL*Plus or SQLcl@vwait.sql
-- No parameters required-- Shows cumulative statistics since instance startup
Required Privileges
Section titled “Required Privileges”- SELECT on V$WAITSTAT
- Generally available to most database users
Sample Output
Section titled “Sample Output”Buffer Busy Waits
CLASS COUNT TIME------------------ ------------ ----------1st level bmb 234 12342nd level bmb 45 2343rd level bmb 12 67data block 8901 45678free list 567 2345segment header 1234 5678sort block 89 123system undo block 345 1567system undo header 23 89undo block 789 3456undo header 156 678 ------------ ----------sum 12345 61149
Key Output Columns
Section titled “Key Output Columns”- CLASS: Type of buffer wait (wait class)
- COUNT: Number of buffer busy wait events
- TIME: Total time waited (in centiseconds)
Understanding Wait Classes
Section titled “Understanding Wait Classes”Critical Wait Classes
Section titled “Critical Wait Classes”- data block: User data block contention (most concerning)
- segment header: Space management contention
- free list: Free list management waits (pre-ASSM)
- undo header: Undo segment header contention
Index-Related Waits
Section titled “Index-Related Waits”- 1st level bmb: Index root block waits
- 2nd level bmb: Index branch block waits
- 3rd level bmb: Index branch block waits (deeper levels)
System Waits
Section titled “System Waits”- system undo block: System undo segment blocks
- system undo header: System undo segment headers
- undo block: Regular undo blocks
- undo header: Regular undo segment headers
Performance Analysis
Section titled “Performance Analysis”High-Impact Wait Classes
Section titled “High-Impact Wait Classes”-
data block (>1000 waits):
- Hot table blocks
- Concurrent DML on same blocks
- Small tables with high update rates
-
segment header (>500 waits):
- Extent allocation contention
- High insert rates with manual space management
- Consider ASSM (Automatic Segment Space Management)
-
undo header (>300 waits):
- Too few undo segments
- High transaction rates
- Undo tablespace contention
Troubleshooting Priorities
Section titled “Troubleshooting Priorities”- Focus on highest COUNT values first
- Consider TIME per wait: TIME/COUNT ratio
- Compare against instance uptime for frequency
Common Use Cases
Section titled “Common Use Cases”Performance Bottleneck Analysis
Section titled “Performance Bottleneck Analysis”-- During application performance issues@vwait.sql-- Look for high data block or segment header waits
Baseline Establishment
Section titled “Baseline Establishment”-- Capture during normal operations@vwait.sql-- Compare with problem periods
Space Management Review
Section titled “Space Management Review”-- Analyze segment header and free list waits@vwait.sql-- Consider tablespace management changes
Troubleshooting Strategies
Section titled “Troubleshooting Strategies”For data block waits
Section titled “For data block waits”-
Identify hot tables:
SELECT owner, object_name, object_typeFROM dba_objectsWHERE data_object_id IN (SELECT obj FROM v$bhWHERE tch > 1000 -- high touch count); -
Reduce block contention:
- Increase PCTFREE to reduce rows per block
- Partition hot tables
- Use hash partitioning for even distribution
For segment header waits
Section titled “For segment header waits”-
Enable ASSM for new tablespaces:
CREATE TABLESPACE ts_nameEXTENT MANAGEMENT LOCALSEGMENT SPACE MANAGEMENT AUTO; -
Increase extent sizes to reduce allocations
-
Pre-allocate space for high-growth objects
For undo waits
Section titled “For undo waits”-
Add more undo segments:
-- Check current undo segmentsSELECT segment_name, status, bytes/1024/1024 mbFROM dba_segmentsWHERE segment_type = 'TYPE2 UNDO'; -
Increase UNDO_TABLESPACE size
-
Tune UNDO_RETENTION parameter
For index waits (bmb)
Section titled “For index waits (bmb)”- Reverse key indexes for right-hand inserts
- Hash partitioning for index distribution
- Increase sequence CACHE size
Advanced Analysis
Section titled “Advanced Analysis”Calculate Wait Ratios
Section titled “Calculate Wait Ratios”-- Average wait time per eventSELECT class, count, time, ROUND(time/NULLIF(count,0), 2) avg_wait_time_csFROM v$waitstatWHERE count > 0ORDER BY count DESC;
Monitor Changes Over Time
Section titled “Monitor Changes Over Time”-- Take multiple snapshots and compare-- Look for trending increases in specific wait classes
Related Scripts
Section titled “Related Scripts”- Hot Blocks Analysis - Find specific contended blocks
- Latch Wait Summary - Related latch contention
- Buffer Cache Statistics - Overall buffer cache performance
- Active Session Waits - Current session wait events