Cookbook recipe

Tune shared_buffers for your workload

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source
Estimated investigation4 min

Scenario

shared_buffers is at the tiny default and the database constantly re-reads pages from the OS cache. Right-sizing it improves cache hit rates. Diagnose it Check the buffer cache hit ratio: SELECT round(100*sum(blks_hit)/greatest(sum(blks_hit)+sum(blks_read),1),2) AS cache_hit_pct FROM pg_stat_database;…

Investigation Path

shared_buffers is at the tiny default and the database constantly re-reads pages from the OS cache. Right-sizing it improves cache hit rates.

Diagnose it

Check the buffer cache hit ratio:

SELECT round(100*sum(blks_hit)/greatest(sum(blks_hit)+sum(blks_read),1),2) AS cache_hit_pct
FROM pg_stat_database;

Why it happens

shared_buffers is PostgreSQL’s own page cache. Too small and it leans entirely on the OS cache with extra copying; too large and it competes with the OS cache and other memory. A common starting point is ~25% of RAM.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • How to fix it
  • Prevent it next time
  • Related & next steps
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Career Impact

This scenario builds production judgment and operational confidence under pressure.

Open Career Dashboard →

Keep going

Related & next steps

Was this helpful?

← All cookbook recipes