Lesson 7 of 7

Online VACUUM, REINDEX, and Table Rewrites

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

The one thing to understand first

Over time tables and indexes accumulate bloat — dead tuples and empty space left by MVCC. There are two fundamentally different ways to deal with it: reclaiming space for reuse within the object (online, cheap) versus physically shrinking the object and returning space to the OS (expensive, traditionally blocking). Choosing the wrong one causes outages.

Routine VACUUM reclaims space for reuse without shrinking the file; returning space to the OS is a separate, far more expensive operation — and there is an online tool for every job, so you should never need the blocking one. Match the tool to the goal and bloat cleanup is invisible to users.

Plain VACUUM: online, but doesn’t shrink files

Regular VACUUM (and autovacuum) marks <a class="sev1-termlink" href="https://thesev1database.com/glossary/dead-tuple/" title="Dead tuple">dead tuple space reusable and updates the free space and visibility maps. It runs with a weak lock that allows concurrent reads and writes. What it does not do is return space to the operating system — the file stays the same size, with free space inside it for future rows. For steady-state churn this is exactly what you want, and it should be handled automatically by a well-tuned autovacuum.

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:

  • VACUUM FULL: shrinks, but locks everything
  • REINDEX CONCURRENTLY: online index rebuild
  • pg_repack: online table compaction
  • Layer 3 — Watch it happen on your own database
  • Layer 4 — The levers this hands you
  • Layer 5 — What an Oracle DBA should expect vs what they get
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Was this helpful?

← Back to 03 — Operations: Zero-Downtime Deployments