Cookbook recipe

The buffer manager: clock-sweep eviction

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

Scenario

When shared_buffers is full and a new page is needed, something must be evicted. The clock-sweep algorithm chooses the victim. Diagnose it Inspect buffer usage with the pg_buffercache extension: CREATE EXTENSION IF NOT EXISTS pg_buffercache; SELECT…

Investigation Path

When shared_buffers is full and a new page is needed, something must be evicted. The clock-sweep algorithm chooses the victim.

Diagnose it

Inspect buffer usage with the pg_buffercache extension:

CREATE EXTENSION IF NOT EXISTS pg_buffercache;
SELECT count(*) FROM pg_buffercache WHERE isdirty;

Why it happens

Each buffer has a usage counter. The clock sweep walks buffers, decrementing counters; a buffer with count zero and no pin is evicted (written first if dirty). Frequently-used pages keep getting re-referenced and survive.

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