Postgres 19's REPACK: Online Bloat Recovery Without Downtime
Postgres tables accumulate dead tuples over time due to its MVCC architecture. When rows are updated or deleted, old versions remain on disk. While autovacuum marks this space for reuse within the table, it cannot shrink the physical file or return space to the OS. High-churn tables eventually accumulate significant bloat, wasting disk capacity and degrading query performance through excess page reads.
Before Postgres 19, database teams faced painful tradeoffs. VACUUM FULL was built-in but required exclusive locks causing lengthy downtime on large tables. Third-party tools like pg_repack operated externally with trigger overhead, while pg_squeeze improved the approach using logical decoding and background workers but still required extension installation and careful configuration.
Postgres 19 integrates REPACK as a native SQL command that eliminates these compromises. Running with the CONCURRENTLY option allows tables to remain fully readable and writable during the rebuild, holding an exclusive lock only during the final swap. Beyond reclaiming wasted space, REPACK can physically cluster rows by index to improve I/O locality for range queries—functionality similar to the legacy CLUSTER command but without locks. Test cases showed tables reclaiming roughly half their physical size within seconds.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.