Hot Blocks Analysis (hotblocks.sql)
What This Script Does
Section titled “What This Script Does”This script identifies “hot blocks” in the buffer cache that are causing cache buffers chains latch contention. It:
- Finds cache buffers chains latches with high sleep counts
- Maps these latches to specific database blocks
- Identifies the segments (tables/indexes) containing these hot blocks
- Shows the touch count (TCH) indicating how frequently blocks are accessed
The Script
Section titled “The Script”set lines 132
select /*+ ordered */ e.owner ||'.'|| e.segment_name segment_name, e.partition_name, e.segment_type, e.extent_id extent#, x.dbablk - e.block_id + 1 block#, x.tch, l.child#from v$latch_children l, x$bh x, dba_extents ewhere l.name = 'cache buffers chains' and l.sleeps > &sleep_count and x.hladdr = l.addr and e.file_id = x.file# and x.dbablk between e.block_id and e.block_id + e.blocks - 1/-- Basic usage@hotblocks.sql
-- When prompted, enter:-- sleep_count: Minimum number of sleeps (e.g., 100)Parameters
Section titled “Parameters”The script prompts for:
- &sleep_count - Minimum sleep count threshold for latches to investigate
Required Privileges
Section titled “Required Privileges”SELECT ON V$LATCH_CHILDRENSELECT ON X$BHSELECT ON DBA_EXTENTSSample Output
Section titled “Sample Output”SEGMENT_NAME PARTITION_NAME SEGMENT_TYPE EXTENT# BLOCK# TCH CHILD#------------------------- -------------- --------------- ---------- ---------- ------- ----------HR.EMPLOYEES TABLE 3 142 255 1024HR.EMPLOYEES_PK INDEX 1 47 198 1024SALES.ORDERS TABLE 15 3891 312 2048SALES.ORDER_ITEMS P_2024_01 TABLE PARTITION 8 892 201 2048Key Output Columns
Section titled “Key Output Columns”- SEGMENT_NAME - Owner and name of the hot segment
- PARTITION_NAME - Partition name if applicable
- SEGMENT_TYPE - Type of segment (TABLE, INDEX, etc.)
- EXTENT# - Extent number within the segment
- BLOCK# - Block number within the extent
- TCH - Touch count (number of times block accessed)
- CHILD# - Child latch number
Common Use Cases
Section titled “Common Use Cases”Diagnose Application Scalability Issues
@hotblocks.sql-- Enter: 1000 for sleep_count-- Look for blocks with very high TCH valuesIdentify Contention Points
@hotblocks.sql-- Enter: 100 for sleep_count-- Focus on segments appearing multiple timesTroubleshooting Hot Blocks
Section titled “Troubleshooting Hot Blocks”Common Causes:
- Primary key index root blocks - Frequent inserts using sequences
- Hot table blocks - Tables with high concurrent updates to same blocks
- Segment header blocks - Frequent space management operations
Resolution Strategies:
- For indexes: Consider reverse key indexes or hash partitioning
- For tables: Use ASSM, increase PCTFREE, or partition tables
- For sequences: Increase sequence cache size or use NOORDER
- Application changes: Reduce contention through design changes
Additional Analysis:
-- Get more details about a specific hot blockSELECT * FROM v$bhWHERE file# = &file_numberAND dbablk = &block_number;
-- Check current latch statisticsSELECT * FROM v$latch_childrenWHERE name = 'cache buffers chains'ORDER BY sleeps DESC;Related Scripts
Section titled “Related Scripts”- Blocking Locks - Find blocking sessions
- Buffer Pool Statistics - Buffer cache analysis
- Latch Statistics - Overall latch contention