Postgres 19 introduces REPACK, a built-in SQL command for rebuilding bloated tables and reclaiming disk space. Updates and deletes leave old row versions behind; autovacuum makes that space reusable inside the table but does not shrink the file or return space to the operating system. Previously, shrinking a table meant accepting a prolonged lock with VACUUM FULL, rebuilding the database, or relying on extensions such as pg_repack or pg_squeeze. REPACK (CONCURRENTLY) uses logical decoding to capture changes while it creates a replacement table, then swaps it in under a brief lock, keeping the table readable and writable during most of the work. REPACK can also order rows to match an index, potentially improving range-query locality; VERBOSE reports progress and ANALYZE refreshes planner statistics.
A test rebuilding a 493 MB table reduced it to 228 MB: VACUUM FULL took 2.7 seconds, ordinary REPACK 5.9 seconds, and REPACK (CONCURRENTLY) 9.4 seconds. The online version takes longer because it captures and replays concurrent changes, and temporarily needs room for the table and indexes to exist twice. It requires a logged, nonpartitioned heap table with an indexable primary key, and only one concurrent operation can run per database at a time. A key safety caveat is that a long-running transaction with an old snapshot could see the table as empty during the final swap. Routine cleanup remains autovacuum’s job; use REPACK when substantial bloat needs to be returned to the OS or when physical row ordering could benefit a workload.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.