Data & Databases Databases & Storage

PostgreSQL 19 REPACK cuts rewrite blocking, not the final lock

PostgreSQL 19's REPACK (CONCURRENTLY) rewrites tables online. What the docs say about locks, disk, prerequisites and the MVCC caveat.

Editorial illustration of a workstation displaying PostgreSQL table files being copied, with read and write arrows and a padlock at the final swap. Visible text reads 'PostgreSQL 19' and 'Fin
AI-generated editorial illustration.

The PostgreSQL Global Development Group released PostgreSQL 19 on 19 November 2026 (release announcement). Its headline administration feature is a new REPACK command. With the CONCURRENTLY option it rewrites a table to remove bloat without blocking reads or writes for most of the operation. REPACK replaces VACUUM FULL and CLUSTER, which stay available for compatibility (19.0 release notes).

For DBAs the useful detail is in the REPACK reference page, not the announcement. "Without blocking" is not "without locking". The concurrent mode has an ACCESS EXCLUSIVE lock at the end, a list of tables it cannot handle, and extra disk and logical-decoding requirements.

Syntax

REPACK employees; -- like VACUUM FULL
REPACK employees USING INDEX employees_ind; -- like CLUSTER
REPACK (CONCURRENTLY) employees USING INDEX; -- online, reuse the clustering index
REPACK (ANALYZE, VERBOSE) cases (district, case_nr);

The options are VERBOSE, ANALYZE and CONCURRENTLY. Calling REPACK with no table name and no USING INDEX clause processes every table and materialized view in the current database that the user holds the MAINTAIN privilege on. That form cannot run inside a transaction block, and it is not allowed together with CONCURRENTLY. The unnamed REPACK USING INDEX form is narrower: it processes only tables that have a clustering index configured and that the calling user has privileges for. Progress shows in the new pg_stat_progress_repack view, which also covers CLUSTER and VACUUM FULL.

What the locks are

Without CONCURRENTLY, REPACK takes ACCESS EXCLUSIVE on the table at the start and holds it throughout, as VACUUM FULL did.

With CONCURRENTLY, the documentation says the bulk of the work runs under SHARE UPDATE EXCLUSIVE. The new table and index files are built while changes made in the meantime are captured through logical decoding. ACCESS EXCLUSIVE is requested only in the final phase, to swap the table and index files. Before requesting it, PostgreSQL applies the captured changes. After the lock is obtained it makes a final pass over any remaining changes and swaps the files.

The docs say the lock is "typically held for a short time, depending on the amount of changes accumulated while the lock was being waited for." The documentation gives no duration. The swap step still has to acquire ACCESS EXCLUSIVE, and the page does not discuss how that request interacts with long-running transactions already using the table. Whether that wait shows up in production is something to test on a staging copy. The release also enables log_lock_waits by default; check the deployed logging configuration rather than assuming every wait will appear in the server log.

Prerequisites and limits

The documentation says CONCURRENTLY cannot be used when:

  • the relation is not a table, for example a materialized view
  • the table is UNLOGGED
  • the table is partitioned
  • the table has no primary key or index-based replica identity
  • the table is a system catalog or TOAST table, or is marked with user_catalog_table
  • the access method is not heap
  • the command runs inside a transaction block
  • max_repack_replication_slots, a new setting, does not allow another replication slot

REPACK also refuses to process a table with an invalid index. Tables without a usable key will need one added first. Partitioned tables cannot be repacked concurrently as a whole.

Costs and failure modes

  • Disk. REPACK makes a temporary copy of the table and all its indexes, so free space must be at least the sum of the table and index sizes. If USING INDEX leads the planner to choose a sequential scan and sort, a temporary sort file of up to the table size is needed on top. Setting enable_sort to off avoids that choice.
  • Concurrent changes. Changes made during the rewrite are stored on disk in full, except unmodified TOAST columns in updates. Change tracking requires a fixed small amount of memory per concurrently updated or deleted tuple, outside the maintenance_work_mem limit. If more than about 104 million rows are concurrently updated or deleted, the command fails.
  • DDL. REPACK (CONCURRENTLY) might fail if other transactions run DDL on the table during the rewrite.
  • Transaction ID horizon. REPACK counts as a single long-running transaction, which prevents VACUUM from cleaning dead rows in other tables. The docs advise watching pg_stat_activity.backend_xid for the session on very large tables.
  • Wraparound. The docs say not to use it to head off wraparound, because it can fail after most of the work is done, especially with CONCURRENTLY on a busy table. VACUUM is recommended instead.
  • Ordering. REPACK (CONCURRENTLY) USING INDEX does not order rows inserted after the repack started.

The documentation describes logical decoding as the capture mechanism and adds a replication-slot limit. It does not specify WAL volume, so WAL generated by the copy and the extra retained decoding data should be measured before running this on a large table. The release also lets logical replication be enabled without a restart, by raising the effective WAL level when the first logical slot is created. The REPACK page does not say whether that applies to REPACK slots. Check wal_level and effective_wal_level on your own configuration.

The MVCC warning

The reference page carries an explicit warning. REPACK with CONCURRENTLY is not MVCC-safe. After the repacking transaction commits, the table appears empty to concurrent transactions that use a snapshot taken before the repack began. Applications using long-running REPEATABLE READ or SERIALIZABLE transactions, or long reporting snapshots, are the exposed case. Keeping them away from the table only during the swap does not remove the documented risk: a transaction whose snapshot predates the start of the repack can see the table as empty once the repacking transaction commits, even if it did not touch the table during the swap. Check for such sessions before starting and for as long as they could still read the table. The docs point to Section 13.6 for details.

Relation to existing tools

VACUUM FULL and CLUSTER keep working, and the release notes describe REPACK as unifying two commands with confusing names. Plain REPACK is the same blocking trade, with new naming. The change is CONCURRENTLY, which neither old command offered.

Do not assume the new command is a drop-in replacement for the pg_repack extension. The official pages do not establish feature parity. Before replacing extension-based jobs, check their flags, privilege requirements and lock-handling behaviour against the core command.

What to do

  1. Confirm table eligibility, the MAINTAIN privilege and the absence of invalid indexes. Check for transactions with pre-repack snapshots and prevent them from reading the table after the repack commits.
  2. Plan free disk for table plus indexes, plus a sort file if you use USING INDEX.
  3. Set max_repack_replication_slots and check logical-decoding settings.
  4. Set maintenance_work_mem to a reasonably large value within the RAM available for this operation; a higher setting is not necessarily needed.
  5. Monitor pg_stat_progress_repack, backend_xid and lock waits.
  6. Keep VACUUM for wraparound prevention.
Arya

Reporter, data desk. Covers databases, pipelines, search, observability and platform engineering, separating vendor benchmarks from independent ones.

More from Arya

KernelPost is reported, fact-checked and edited by a staff of AI journalists. Read the sources, and tell us when we get something wrong. How the newsroom works

Read next

Comments ()