Postgres 19 REPACK (CONCURRENTLY): RIP pg_repack?
👉 Give your AI agent PostgresAI: npx pgai skills
Tip: watch the video version on YouTube: it has the charts from our DBLab Forge study and animations of every mechanism we talk about.
Episode description
Nik and Kirk discuss REPACK (CONCURRENTLY), the new way in Postgres 19 to remove table bloat without long locks: how we got here (pgcompacttable, VACUUM FULL, pg_repack, pg_squeeze), why "concurrently" here does not mean what it means for REINDEX CONCURRENTLY, and what our DBLab Forge experiments showed. The final file swap still needs an ACCESS EXCLUSIVE lock: at 2,000 TPS with the default lock_timeout = 0, one 60-second SELECT froze all reads and writes for 57 s. Then lock_timeout with one attempt vs pg_repack's retry loop, autovacuum, the MVCC caveat, and when to use which tool today.
Links
Here are some links to things they mentioned:
Main link
- [17:32] DBLab Forge study: REPACK (CONCURRENTLY) in Postgres 19 (brief): https://console.postgres.ai/shared/brief/01a22e1d-4f42-7e46-996e-6664e89d0fc2
REPACK and its history
- [00:29] REPACK (Postgres 19 docs): https://www.postgresql.org/docs/19/sql-repack.html
- [01:12] Squeezing tables with Postgres 19 (Álvaro Herrera, EDB blog): https://www.enterprisedb.com/blog/squeezing-tables-postgres-19
- [09:08] Table Repacking, done right (Álvaro Herrera and Antonín Houska, PGConf.EU 2025 slides): https://www.postgresql.eu/events/pgconfeu2025/sessions/session/7094/slides/772/herrera-houska-repack-2025.pdf
- [03:19] pgcompacttable: https://github.com/dataegret/pgcompacttable
- [04:55] vacuum_truncate storage parameter: https://www.postgresql.org/docs/19/sql-createtable.html#RELOPTION-VACUUM-TRUNCATE
- [06:38] pg_repack: https://github.com/reorg/pg_repack
- [09:08] pg_squeeze: https://github.com/cybertec-postgresql/pg_squeeze
- [11:55] PostgreSQL 14.4 release notes (CREATE/REINDEX INDEX CONCURRENTLY fix): https://www.postgresql.org/docs/release/14.4/
Locks and settings
- [05:54] Explicit locking, the lock conflict table: https://www.postgresql.org/docs/19/explicit-locking.html#LOCKING-TABLES
- [16:23] lock_timeout: https://www.postgresql.org/docs/19/runtime-config-client.html#GUC-LOCK-TIMEOUT
- [23:34] pg_repack lock_exclusive(), the retry loop (100 ms steps up to 1 s): https://github.com/reorg/pg_repack/blob/ver_1.5.3/bin/pg_repack.c
- [27:56] deadlock_timeout: https://www.postgresql.org/docs/19/runtime-config-locks.html#GUC-DEADLOCK-TIMEOUT
- [34:49] pg_stat_progress_repack (Postgres 19 progress reporting): https://www.postgresql.org/docs/19/progress-reporting.html
Testing
- [13:44] DBLab Forge: https://postgres.ai/products/dblab-forge
Episodes we referred to
- [09:14] pg_squeeze (with Antonín Houska): https://postgres.fm/episodes/pg_squeeze
- [15:49] Zero-downtime migrations: https://postgres.fm/episodes/zero-downtime-migrations
- [29:28] Slow queries and slow transactions (episode 1): https://postgres.fm/episodes/slow-queries-and-slow-transactions
- [00:29] Postgres 19: https://postgres.fm/episodes/postgres-19
Corrections
Checked after recording against the DBLab Forge study and the Postgres 19 docs:
- [17:20] Case T1 is a 13.02 GiB table, not "20-something" GB.
- [17:53] The red area on the T1 chart is a 6.04 s lock wait span, with 5 s at 0 TPS (not "seven seconds").
- [24:19] The 901.2 GiB run (Case T2: 5.32 h, exploratory, unverified) used a 4 TB network volume (141.9 MiB/s), not local NVMe.
- [34:06] The setting is max_slot_wal_keep_size.
- [34:49] Postgres 19 already has the pg_stat_progress_repack view. It does not show the decoded changes spilled to temporary files: in our edge test, pg_ls_tmpdir() returned 0 rows during the spill.