Skip to content

Buffer Pool Summary by File (vbhstat.sql)

This script analyzes the distribution of database blocks in the Oracle buffer cache across different datafiles. It provides insights into buffer allocation patterns, identifies files with high buffer cache usage, and shows the distribution of dirty blocks that need to be written to disk.

rem vbhstat.sql
rem
ttitle 'Buffer Pool Summary by File'
rem
col file# format 999 heading 'FILE'
col buffer_count format b999999 heading 'BUFFERS'
col distinct_block format b999999 heading 'BLOCKS'
col extra_block format b999999 heading 'EXTRA|BLOCKS'
col dirty_block format b99999 heading 'DIRTY|BLOCKS'
col temp_block format b99999 heading 'TEMP|BLOCKS'
rem
break on report
compute sum -
of buffer_count distinct_block extra_block dirty_block temp_block -
on report
rem
select file#,
count(*) buffer_count,
count( distinct block# ) distinct_block,
count(*) - count( distinct block# ) extra_block,
count( decode( dirty, 'Y', 1 ) ) dirty_block,
count( decode( temp, 'Y', 1 ) ) temp_block
from v$bh
group by file#
/
-- Run the script in SQL*Plus or SQLcl
@vbhstat.sql
-- No parameters required
-- Shows current buffer cache state
  • SELECT on V$BH (buffer header view)
  • Typically requires DBA role due to V$BH access
Buffer Pool Summary by File
FILE BUFFERS BLOCKS EXTRA DIRTY TEMP
BLOCKS BLOCKS BLOCKS
---- -------- ------- ------ ------ ------
1 45678 45234 444 2345 0
2 23456 23123 333 1234 0
3 12345 12234 111 567 0
4 8901 8845 56 234 0
5 5678 5634 44 123 0
10 234 234 0 45 45
---- -------- ------- ------ ------ ------
sum 96292 95304 988 4548 45
  • FILE: Datafile number
  • BUFFERS: Total number of buffers from this file in cache
  • BLOCKS: Number of distinct blocks cached (unique blocks)
  • EXTRA BLOCKS: Duplicate blocks in cache (BUFFERS - BLOCKS)
  • DIRTY BLOCKS: Modified blocks not yet written to disk
  • TEMP BLOCKS: Temporary tablespace blocks in cache
  • High BUFFERS: Files with heavy read activity or large objects
  • BLOCKS vs BUFFERS: Indicates block access patterns
  • EXTRA BLOCKS: Multiple copies of same block (normal for busy blocks)
  • High DIRTY BLOCKS: Files with heavy write activity
  • Dirty Block Ratio: DIRTY/BUFFERS shows write intensity
  • Temp Files: Usually show in temporary tablespace files
  • Large Buffer Counts: Heavily accessed datafiles
  • High Dirty Ratios: Write-intensive tablespaces
  • Low Buffer Counts: Infrequently accessed files
  1. High Buffer Counts: Most actively read files
  2. High Dirty Block Counts: Write-intensive files
  3. High Extra Block Ratios: Frequently re-read blocks
  • Extra Blocks > 10%: May indicate cache pressure
  • Even Distribution: Good for balanced I/O
  • Concentrated Activity: May indicate hot spots
  • Read-Heavy Files: High buffers, low dirty blocks
  • Write-Heavy Files: High dirty block ratios
  • Balanced Files: Moderate buffers and dirty blocks
-- During I/O performance issues
@vbhstat.sql
-- Identify files consuming most buffer cache
-- Analyze buffer cache distribution
@vbhstat.sql
-- Plan datafile placement and buffer cache sizing
-- Understand file access patterns
@vbhstat.sql
-- Optimize storage layout and I/O distribution
  1. Large Table Scans: Consider indexing or partitioning
  2. Hot Tables: Consider spreading across multiple files
  3. Poor SQL: Optimize queries accessing these files
  1. DBWR Performance: Check database writer efficiency
  2. Checkpoint Frequency: Review checkpoint intervals
  3. Redo Log Sizing: Ensure adequate redo log capacity
  1. File Placement: Consider spreading hot objects
  2. Tablespace Design: Review tablespace file allocation
  3. Parallel Processing: May cause uneven access patterns
-- Map file numbers to actual files
SELECT file_id, file_name, tablespace_name
FROM dba_data_files
WHERE file_id IN (/* high buffer count files */);
-- Check datafile I/O statistics
SELECT name, phyblkrd, phyblkwrt, readtim, writetim
FROM v$filestat f, v$datafile d
WHERE f.file# = d.file#
ORDER BY phyblkrd DESC;
-- Buffer pool configuration
SELECT name, block_size, current_size, buffers
FROM v$buffer_pool;