Latch Wait Summary (latchsum.sql)
What This Script Does
Section titled “What This Script Does”This script provides a summary of Oracle latch contention by analyzing which latches processes are currently waiting for. It groups processes by the specific latch they are waiting on and shows the total number of sessions waiting for each latch type, helping identify latch bottlenecks.
Script
Section titled “Script”rem latchsum.sqlremttitle 'Latch Wait Summary'remcol latchwait format a8 heading 'LATCH|WAIT'col name format a32 heading 'LATCH NAME'col session_count format 9999 heading 'SESSION|COUNT'rembreak on reportcompute sum of session_count on reportremselect latchwait, name, count(*) session_count from v$process p, v$latch l where p.latchwait = l.addr(+) group by p.latchwait, name;
-- Run the script in SQL*Plus or SQLcl@latchsum.sql
-- No parameters required-- Shows current latch waits at time of execution
Required Privileges
Section titled “Required Privileges”- SELECT on V$PROCESS
- SELECT on V$LATCH
- Typically requires DBA role
Sample Output
Section titled “Sample Output”Latch Wait Summary
LATCH LATCH NAME SESSIONWAIT COUNT-------- -------------------------------- ------- cache buffers chains 5 redo allocation 3 shared pool 2 library cache 1 -------sum 11
Key Output Columns
Section titled “Key Output Columns”- LATCH WAIT: Latch address (null if no wait)
- LATCH NAME: Name of the latch being waited for
- SESSION COUNT: Number of processes waiting for this latch
Understanding Latch Contention
Section titled “Understanding Latch Contention”Common Latch Types and Meanings
Section titled “Common Latch Types and Meanings”- cache buffers chains: Buffer cache block access contention
- redo allocation: Redo log buffer allocation conflicts
- shared pool: Shared pool memory allocation issues
- library cache: SQL parsing and library cache access
- redo copy: Redo log buffer copy mechanism waits
Interpreting Results
Section titled “Interpreting Results”- High session counts: Indicate significant contention points
- Multiple latch types: System-wide performance issues
- Single dominant latch: Specific bottleneck to address
- No waits: System performing well at time of check
Performance Analysis
Section titled “Performance Analysis”Critical Latch Contention Scenarios
Section titled “Critical Latch Contention Scenarios”-
cache buffers chains (>10 sessions):
- Hot blocks causing buffer cache contention
- Consider increasing buffer cache or finding hot blocks
-
redo allocation (>5 sessions):
- Redo log buffer too small or log writer bottleneck
- Increase log buffer size or optimize log writer I/O
-
shared pool (>3 sessions):
- Shared pool memory pressure
- Increase shared pool size or reduce SQL parsing
-
library cache (>2 sessions):
- Hard parsing or library cache locks
- Improve SQL reuse or resolve library cache issues
Common Use Cases
Section titled “Common Use Cases”Performance Troubleshooting
Section titled “Performance Troubleshooting”-- During performance issues@latchsum.sql-- Look for high session counts on specific latches
Proactive Monitoring
Section titled “Proactive Monitoring”-- Include in health check scripts@latchsum.sql-- Baseline normal vs problem periods
Capacity Planning
Section titled “Capacity Planning”-- Monitor latch contention trends@latchsum.sql-- Document growth in latch waits over time
Troubleshooting High Latch Waits
Section titled “Troubleshooting High Latch Waits”For cache buffers chains
Section titled “For cache buffers chains”- Identify hot blocks using hotblocks.sql
- Increase DB_CACHE_SIZE if memory available
- Tune SQL to reduce logical reads
- Consider partitioning for hot tables
For redo allocation
Section titled “For redo allocation”- Increase LOG_BUFFER parameter
- Optimize redo log placement (faster disks)
- Reduce commit frequency in applications
- Check log writer I/O performance
For shared pool
Section titled “For shared pool”- Increase SHARED_POOL_SIZE
- Enable cursor sharing (CURSOR_SHARING=FORCE)
- Pin frequently used packages in shared pool
- Reduce hard parsing through bind variables
Related Scripts
Section titled “Related Scripts”- Detailed Latch Statistics - Comprehensive latch analysis
- Hot Blocks Analysis - Find cache buffers chains contention
- Buffer Cache Analysis - Buffer pool performance
- Active Session Analysis - Current session activity