Cookbook recipe

Reclaim bloat without downtime

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

Scenario

A table grew to 3x its real data size from churn. VACUUM FULL would reclaim it but takes an exclusive lock. pg_repack does it online. Diagnose it Estimate bloat, then choose a tool: -- rough table…

Investigation Path

A table grew to 3x its real data size from churn. VACUUM FULL would reclaim it but takes an exclusive lock. pg_repack does it online.

Diagnose it

Estimate bloat, then choose a tool:

-- rough table size vs live tuples
SELECT relname, pg_size_pretty(pg_total_relation_size(relid)) AS total,
       n_live_tup, n_dead_tup
FROM pg_stat_user_tables ORDER BY pg_total_relation_size(relid) DESC LIMIT 10;

Why it happens

Plain VACUUM marks dead tuples reusable but does not return space to the OS. VACUUM FULL rewrites the table compactly but holds an ACCESS EXCLUSIVE lock. pg_repack rebuilds online with only brief locking.

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