Skip to content

Latch Statistics Ratios (vlatchr.sql)

This script analyzes latch performance statistics showing get ratios, miss percentages, and sleep patterns for identifying concurrency issues and system bottlenecks. Latches are lightweight serialization mechanisms that protect shared data structures in Oracle’s SGA. High miss ratios or sleep percentages indicate contention that can severely impact performance, especially in high-concurrency RAC environments.

rem vlatchr.sql
rem
ttitle 'Latch Statistics Ratios'
rem
set lines 110
set trimspool on
col name format a27 heading 'NAME'
col pid format 90 heading 'PID'
col gets format b999999999 heading 'GETS'
col misses format b9999999 heading 'MISSES'
col miss_pct format b999.9 heading 'MISSES|PCT'
col sleeps format b9999999 heading 'SLEEPS'
col sleeps_pct format b999.9 heading 'SLEEPS|PCT'
col immediate_gets format b99999999 heading 'IMMEDIATE|GETS'
col immediate_misses format b99999999 heading 'IMMEDIATE|MISSES'
col immed_miss_pct format b99999999 heading 'IMMEDIATE|MISSES|PCT'
rem
break on report
compute sum of gets misses sleeps immediate_gets immediate_misses on report
rem
select n.name, h.pid,
l.gets,
l.misses,
l.misses / decode(l.gets, 0, 1, l.gets)*100 miss_pct,
l.sleeps,
l.sleeps / decode(l.gets, 0, 1, l.gets)*100 sleeps_pct,
l.immediate_gets,
l.immediate_misses,
l.immediate_misses/decode(l.immediate_gets + l.immediate_misses,
0, 1,
l.immediate_gets + l.immediate_misses) * 100
immed_miss_pct
from v$latchholder h, v$latchname n, v$latch l
where l.latch# = n.latch#
and l.addr = h.laddr(+)
order by n.name;
  • Comprehensive Latch Analysis: Shows all latch types with detailed statistics
  • Miss Ratio Calculation: Calculates miss percentages for immediate assessment
  • Sleep Pattern Analysis: Shows sleep statistics indicating contention severity
  • Immediate Gets Analysis: Tracks immediate mode latch operations
  • Process Correlation: Shows which processes are holding latches
  • Summary Statistics: Provides totals across all latch types
  • Contention Identification: Highlights problematic latch contention patterns
@vlatchr.sql

No parameters required - analyzes all latch statistics.

SELECT on V$LATCHHOLDER
SELECT on V$LATCHNAME
SELECT on V$LATCH
Latch Statistics Ratios
NAME PID GETS MISSES MISSES SLEEPS SLEEPS IMMEDIATE IMMEDIATE IMMEDIATE
PCT PCT GETS MISSES MISSES PCT
--------------------------- ------ --------- ------- ------ ------- ------ --------- --------- ---------
cache buffers chains 0 45678901 123456 0.3 45678 0.1 12345678 234567 1.9
cache buffers lru chain 0 8901234 23456 0.3 5678 0.1 2345678 45678 1.9
checkpoint queue latch 0 567890 1234 0.2 234 0.0 123456 2345 1.9
enqueue hash chains 0 3456789 12345 0.4 2345 0.1 456789 8901 1.9
library cache 0 12345678 45678 0.4 8901 0.1 1234567 23456 1.9
library cache pin 0 6789012 23456 0.3 4567 0.1 789012 15678 1.9
library cache pin allocation 0 2345678 8901 0.4 1234 0.1 345678 6789 1.9
redo allocation 0 8901234 34567 0.4 6789 0.1 1234567 25678 2.0
redo copy 0 4567890 15678 0.3 2345 0.1 567890 11234 1.9
session allocation 0 1234567 4567 0.4 891 0.1 234567 4567 1.9
shared pool 0 6789012 23456 0.3 4567 0.1 891234 17890 2.0
--------- ------- ------ ------- ------ --------- --------- ---------
sum 101234567 356789 0.4 77689 0.1 19876543 396789 2.0
  • NAME: Latch name identifying the protected resource
  • PID: Process ID currently holding the latch (0 = not held)
  • GETS: Total number of successful latch gets
  • MISSES: Number of failed initial get attempts
  • MISSES PCT: Percentage of gets that initially failed
  • SLEEPS: Number of times process slept waiting for latch
  • SLEEPS PCT: Percentage of gets that required sleeping
  • IMMEDIATE GETS: Number of immediate mode get attempts
  • IMMEDIATE MISSES: Number of failed immediate gets
  • IMMEDIATE MISSES PCT: Failure rate for immediate gets
-- Standard latch acquisition:
-- 1. Initial get attempt
-- 2. If busy, spin for short period
-- 3. If still busy, sleep and retry
-- 4. Process repeats until successful
-- Immediate latch acquisition:
-- 1. Single get attempt
-- 2. If busy, return immediately with failure
-- 3. No spinning or sleeping
-- 4. Used when alternative action possible
-- Miss percentage thresholds:
-- <1%: Excellent performance
-- 1-2%: Good performance
-- 2-5%: Moderate contention
-- >5%: High contention (investigation needed)
-- Sleep percentage indicates severity:
-- <0.1%: Minimal contention
-- 0.1-1%: Moderate contention
-- >1%: Severe contention (performance impact)
-- High sleeps indicate sustained contention
  1. Concurrency Troubleshooting

    • Identify latch contention bottlenecks
    • Diagnose RAC-specific performance issues
    • Support high-concurrency application optimization
    • Resolve scalability limitations
  2. Performance Analysis

    • Analyze system bottlenecks under load
    • Support capacity planning decisions
    • Validate system tuning effectiveness
    • Identify architectural limitations
  3. RAC Performance Tuning

    • Diagnose inter-instance coordination issues
    • Optimize cache fusion performance
    • Support RAC-specific parameter tuning
    • Resolve cluster-wide contention
  4. Application Optimization

    • Identify application-induced contention
    • Support connection pooling optimization
    • Validate transaction design efficiency
    • Guide application architecture decisions
-- Most critical latch for OLTP:
-- Protects buffer cache hash chains
-- High contention indicates hot blocks
-- Optimization: Reduce logical reads, improve SQL efficiency
-- Protects shared SQL and PL/SQL code:
-- High contention indicates parse issues
-- Causes: Hard parsing, cursor sharing problems
-- Optimization: Improve cursor reuse, bind variables
-- Protects redo log buffer allocation:
-- High contention in write-heavy systems
-- Causes: Large redo generation, small log buffer
-- Optimization: Increase log buffer, reduce redo generation
-- Protects shared pool memory allocation:
-- High contention during memory allocation
-- Causes: Frequent parsing, memory fragmentation
-- Optimization: Increase shared pool, reduce parsing
-- Sustained contention characteristics:
-- Consistently high miss ratios
-- Regular sleep patterns
-- System-wide performance impact
-- Requires architectural changes
-- Application pattern indicators:
-- Contention during specific operations
-- Correlation with application events
-- User load correlation
-- Optimization through application design
-- Memory allocation optimization:
-- Increase relevant SGA components
-- Optimize shared pool sizing
-- Adjust buffer cache allocation
-- Configure appropriate PGA settings
-- Latch-related parameter optimization:
-- _SPIN_COUNT: Adjust spin iterations
-- CURSOR_SHARING: Improve cursor reuse
-- SESSION_CACHED_CURSORS: Reduce parsing
-- DB_BLOCK_SIZE: Optimize for workload
-- Reduce latch pressure through:
-- Improved SQL efficiency (fewer logical reads)
-- Better cursor sharing (bind variables)
-- Reduced parsing (statement caching)
-- Optimized transaction design
-- Connection optimization:
-- Connection pooling implementation
-- Reduced connection churning
-- Session state optimization
-- Transaction scope minimization
-- RAC latch optimization:
-- Reduce inter-instance coordination
-- Optimize sequence caching
-- Implement application partitioning
-- Use instance-specific services
-- RAC workload optimization:
-- Partition workload by instance
-- Use connection load balancing
-- Implement service-based routing
-- Optimize parallel execution
-- For high miss percentages:
-- Identify specific latch types with issues
-- Correlate with application activity
-- Analyze wait events for related waits
-- Review system resource utilization
-- Miss ratio reduction:
-- Optimize underlying operations
-- Reduce resource contention
-- Implement application changes
-- Adjust system parameters
-- High sleep percentage indicates:
-- Severe contention requiring process sleeping
-- System resource exhaustion
-- Architectural bottlenecks
-- Need for significant optimization
-- Sleep reduction strategies:
-- Address root cause contention
-- Implement workload distribution
-- Optimize resource allocation
-- Consider architectural changes
-- Correlate with wait events:
-- latch: cache buffers chains
-- latch: shared pool
-- latch: library cache
-- latch: redo allocation
-- Impact analysis:
-- Response time correlation
-- Throughput impact measurement
-- User experience assessment
-- Business impact evaluation
-- Long-term analysis:
-- Miss ratio trend tracking
-- Contention pattern evolution
-- Performance correlation over time
-- Capacity planning support
-- Performance baselines:
-- Normal latch performance levels
-- Expected miss ratios by workload
-- Seasonal variation patterns
-- Growth impact projections
-- Regular assessment:
-- Daily latch performance review
-- Peak period analysis
-- Post-change validation
-- Proactive contention detection
-- Alert thresholds:
-- Miss ratio > 2% for critical latches
-- Sleep ratio > 0.5% for any latch
-- Sustained contention patterns
-- Performance impact correlation
-- Optimization methodology:
-- Focus on highest contention latches first
-- Address root causes, not symptoms
-- Validate changes in test environment
-- Monitor improvement effectiveness
-- Contention prevention:
-- Efficient application design
-- Proper system sizing
-- Regular performance monitoring
-- Proactive capacity planning
-- Monitoring considerations:
-- V$ view queries add minimal overhead
-- Avoid excessive polling frequency
-- Consider monitoring tools impact
-- Balance visibility with performance

This script is essential for:

  1. Concurrency Analysis - Identifying and resolving latch contention in high-concurrency environments
  2. Performance Troubleshooting - Diagnosing system bottlenecks and scalability issues
  3. RAC Optimization - Supporting cluster-wide performance tuning and optimization
  4. Capacity Planning - Understanding system limits and planning for growth
  5. Application Optimization - Guiding application design decisions to minimize contention