REPACK (CONCURRENTLY) Is a Write-Traffic Mirror With a 105M-Row Ceiling
Eleven and a half milliseconds. That is every millisecond of ACCESS EXCLUSIVE that REPACK (CONCURRENTLY) held on a 1.9 GB table with 4.2 million dead...
Eleven and a half milliseconds. That is every millisecond of ACCESS EXCLUSIVE that REPACK (CONCURRENTLY) held on a 1.9 GB table with 4.2 million dead tuples: 11.5 ms total, sampled every 2 ms from a second session, against 9,324 ms for VACUUM FULL on the same table. PostgreSQL 19 shipped on 19 November 2026 and that number is the reason DBAs are upgrading.
The number that does not make the announcement posts is on the other side of the trade. Catch-up keeps a fixed-size entry in backend memory for every row another session updates or deletes while the rewrite runs, and the array holding those entries stops growing at 104,857,600 of them. Past that the command fails at the end of a run that may have taken hours, the new heap is discarded, and the disk you freed for it is handed back. Online rebuilds are not free. They are paid for in RAM and in a mirrored copy of your write traffic, and the bill arrives late.
Three Syntaxes, One Statement, One New Capability
Postgres 19 replaces the VACUUM FULL / CLUSTER split with one verb and three modes. Two of them are the old commands under a new name; one is genuinely new.
-- blocking: unordered rewrite, holds ACCESS EXCLUSIVE for the whole run
REPACK orders;
-- blocking: rewrite ordered by an index, holds ACCESS EXCLUSIVE for the whole run
REPACK orders USING INDEX orders_created_at_idx;
-- online: copy under SHARE UPDATE EXCLUSIVE, ACCESS EXCLUSIVE only for the swap
REPACK (CONCURRENTLY) orders;
-- anything above, plus INFO-level progress and a trailing ANALYZE
REPACK (VERBOSE, ANALYZE) orders;
I built 19.0 from source and ran all four against the same table on the same host: 6,000,000 rows of bigint plus a 120-character payload, 70% of rows updated once, then VACUUM, leaving 1,946 MB on disk of which 1,688 MB was heap.
| Form | Wall clock | Total size after | ACCESS EXCLUSIVE window |
|---|---|---|---|
VACUUM FULL | 9,846 ms | 1,123 MB | 9,324 ms |
REPACK | 17,587 ms | 1,123 MB | 17,112 ms |
REPACK USING INDEX | 14,928 ms | 1,122 MB | 14,446 ms |
REPACK (CONCURRENTLY) | 19,434 ms | 1,124 MB | 11.5 ms |
Two things in that table matter more than the rest. All four forms land within 2 MB of each other, so the new syntax reclaims exactly what the old one did, no more. And the online form is the slowest of the four, 19.4 s against 9.8 s, because it performs the same copy and index rebuild and then replays your concurrent writes through a logical decoding worker on top.
Plain REPACK landing slower than VACUUM FULL is the one figure I would not defend past a single run; both rewrite the same bytes, and the difference is likely the repack code path's extra bookkeeping rather than a real cost. The sizes and the lock windows are the parts worth keeping.
The Lock Window Stops Scaling With the Table
Lock timing came from a second autocommit connection polling pg_locks every 2 ms and summing every interval in which the repack backend held AccessExclusiveLock on the table. The same session read pg_stat_progress_repack to label phases, which is also the view you want in a dashboard:
SELECT p.pid,
p.relid::regclass AS relation,
p.command,
p.phase,
p.heap_tuples_scanned,
p.heap_tuples_updated,
p.heap_tuples_deleted,
p.index_rebuild_count,
EXISTS (
SELECT 1 FROM pg_locks l
WHERE l.pid = p.pid
AND l.relation = p.relid
AND l.mode = 'AccessExclusiveLock'
AND l.granted
) AS holds_ael
FROM pg_stat_progress_repack p;
On the 6-million-row table the phases split as 14,912 ms copying the heap, 3,550 ms rebuilding the indexes, and 530 ms replaying the backlog that arrived during the copy. The exclusive lock covers only the tail of that last phase. Under VACUUM FULL the same three phases run with the lock held from the first page read to the last index page written, which is why the window tracked table size exactly: 9,324 ms for 1.1 GB.
Under CONCURRENTLY the window tracks something else: the number of changes still unreplayed at the instant the lock is granted, which is a function of your write rate and how long the request waited in the lock queue. A table taking 5,000 updates per second turns a 200 ms lock wait into 1,000 replayed rows and a proportionally longer hold. The predictor is writes per second, not gigabytes.
The practical difference for a writer is starker than the lock table suggests. A single-row UPDATE issued while the copy phase was running completed in 33 ms. The same statement issued while VACUUM FULL held the table took up to 9.9 s. That is the feature, and it is worth the extra nine seconds of wall clock.
Catch-Up Keeps 8 Bytes Per Touched Row
Every tuple in the new heap carries the repack transaction's xmin, so the rewrite is one long transaction from the visibility layer's point of view. When a concurrent session updates a row that has already been copied, the repack worker has to apply that update to the new heap as well, and to keep the result consistent it increments its command counter. Each replayed change therefore consumes a combo CID, and combo CIDs are held until commit.
That array is where the ceiling lives. From the 19.0 tree I built:
/* src/backend/utils/time/combocid.c */
#define CCID_ARRAY_SIZE 100
if (usedComboCids >= sizeComboCids)
{
int newsize = sizeComboCids * 2;
comboCids = (ComboCidKeyData *)
repalloc(comboCids, sizeof(ComboCidKeyData) * newsize);
sizeComboCids = newsize;
}
MaxAllocSize in src/include/utils/memutils.h is 0x3fffffff, one gigabyte minus one byte. A ComboCidKeyData is two command IDs, 8 bytes. Start at 100 entries and double: 100 × 220 = 104,857,600 entries occupy 838,860,800 bytes, and the next doubling requests 1,677,721,600 bytes. That request exceeds the allocator's limit and the run dies with ERROR: invalid memory alloc request size 1677721600. No GUC raises that limit and no amount of RAM lifts it; the array would have to be moved out of a single palloc.
The documentation states the limit as roughly 104 million changed rows, which matches the arithmetic. Marek Zarychta's field report is what turns it into an operational rule: resident memory grows by about 50 bytes per replayed change, so a backend under a 1 GB memory cap is killed around 18 million changes and takes the cluster down with it in a crash restart, a 4 GB cap carries you to 84.3 million, and an 8 GB cap runs into the hard ceiling first.
The planning inequality is one line: update_rate × expected_duration < 100,000,000, with the duration measured, not guessed. A table absorbing 2,000 updates per second cannot survive a 14-hour rewrite; it fails at hour fourteen with nothing to show for it. Measure the rate over a fixed window rather than trusting the cumulative counter, because n_tup_upd accumulates since the last stats reset:
CREATE TEMP TABLE t0 AS
SELECT n_tup_upd + n_tup_del AS changes, clock_timestamp() AS at
FROM pg_stat_user_tables
WHERE relname = 'orders';
SELECT pg_sleep(60);
WITH rate AS (
SELECT (n_tup_upd + n_tup_del - t0.changes)::numeric
/ extract(epoch FROM clock_timestamp() - t0.at) AS per_sec
FROM pg_stat_user_tables, t0
WHERE relname = 'orders'
)
SELECT round(per_sec) AS changes_per_sec,
round(1e8 / per_sec / 3600, 1) AS hours_to_ceiling,
round(pg_total_relation_size('orders') / 1048576) AS mb
FROM rate;
The Swap Is Not MVCC-Safe, and the Request Queues Behind Readers
The lock window is short, not invisible. REPACK (CONCURRENTLY) waits for transactions that touched the table before the swap and ignores the rest, which produces a hole in snapshot isolation that the documentation flags and that is easy to reproduce:
-- session 1: fix a snapshot before the repack finishes
BEGIN ISOLATION LEVEL REPEATABLE READ;
SELECT count(*) FROM settings;
-- session 2
REPACK (CONCURRENTLY) orders;
-- session 1: the rewrite swapped the relfilenode under this snapshot
SELECT count(*) FROM orders; -- 0
COMMIT;
Measured on 19.0: 0 rows mid-transaction, 6,000,000 after commit, no error and no serialization failure. Any REPEATABLE READ job that touches other tables first and the repacked table later, export jobs and reconciliation checks being the usual suspects, can read an empty table and write that emptiness somewhere you will have to explain later. Set the isolation level to READ COMMITTED, or touch the table in the first statement of the transaction.
The second half of the lock story is the queue, and it is longer than the lock. A read-only transaction holding ACCESS SHARE blocks the swap request, and everything that needs a conflicting lock on the table lines up behind that request, not behind the reader. In my run an idle BEGIN; SELECT count(*) left the AccessExclusiveLock ungranted for 206 ms; a writer with lock_timeout = '200ms' was cancelled inside that window even though its ROW EXCLUSIVE lock was compatible with the reader. The repack finished in 9,923 ms with all 6,000,000 rows intact.
-- SET is its own statement: the command refuses to run inside a transaction block
SET lock_timeout = '500ms';
SET statement_timeout = '6h';
REPACK (CONCURRENTLY) orders;
Wrap the call in a timeout you can survive and retry on the next quiet window. A failed run leaves the table as it was; it does not leave half a rewrite behind.
Five Errors, a Slot Pool, and Four Tools
Every rejection below is the exact message 19.0 GA returned, which is what you will see in a migration script at 02:00:
ERROR: REPACK (CONCURRENTLY) requires a primary key or an index with unique, non-null columnsERROR: cannot repack unlogged relation "ul" concurrentlyERROR: cannot repack partitioned relation "part" concurrentlyERROR: REPACK (CONCURRENTLY) requires a relation namefor the whole-database formERROR: REPACK (CONCURRENTLY) cannot run inside a transaction block, andANALYZEis refused there too
Concurrency is the claim I found least reliable in circulation. Craig Kerstiens' write-up, published against RC1, states that only one concurrent repack may run per database. The shipped code allocates from a slot pool sized by max_repack_replication_slots, default 5, so the pool is five, not one. I started two on separate 2-million-row tables 150 ms apart and both progressed; pg_stat_progress_repack held two rows at once. Treat the limit as five slots and treat running five at once on one disk as a self-inflicted outage.
Space is the other precondition that bites late. You need free space for the table plus its indexes, since two copies exist for the duration, plus the WAL the replication slot retains until the run finishes. Marek's 28 GB table generated 18.8 GB of WAL, peaked at 18.7 GB of additional disk, and finished in 107 seconds; a slow table on a fast-updating database turns those figures into a disk-full incident rather than a slow query. That WAL is the same commit-log bill a queue pays on every write, moved forward into a single maintenance run.
| Tool | In core | Blocking | Write-path cost | Preload needed |
|---|---|---|---|---|
REPACK (CONCURRENTLY) | 19+ | swap only | logical decoding worker | no |
pg_repack | no | swap plus triggers | trigger on every write | no |
pg_squeeze | no | swap only | logical decoding worker | output_plugin_libraries |
VACUUM FULL | yes | whole rewrite | none | no |
The decision is arithmetic, not taste. If the table takes fewer than roughly 100,000,000 divided by your rewrite duration changes, run REPACK (CONCURRENTLY) and let it finish. If it takes more, no amount of RAM saves the run and the answer is pg_repack in batches, which keeps the change log on disk in a table you can inspect. If you have a maintenance window and the rewrite takes minutes, plain REPACK is faster than the online form and the lock costs you nothing. The one case that never changes: measure the update rate first, because the ceiling is a hard address in the allocator and it does not care that your table is only 300 GB.