Jorge Turbica / blog · Blog ← All articles ES · Leer en español
Technologies

PostgreSQL 19 removes bloat without locking the table: REPACK, pinned plans, what breaks

PostgreSQL 19 adds non-blocking REPACK, pinned query plans and read-your-writes on replicas, but turns JIT off and drops RADIUS. What to check first.

Clearing bloat from a large table no longer means locking it for minutes or hours. PostgreSQL 19, released on 19 November 2026, ships REPACK (CONCURRENTLY), which rewrites a table without blocking reads or writes. It also brings a way to pin query plans without touching application code, read-your-writes consistency on standbys, and a list of breaking changes worth reading before you upgrade.

The features that change day-to-day work

REPACK replaces VACUUM FULL and CLUSTER. Until now, reclaiming space from a table with heavy updates and deletes meant holding an ACCESS EXCLUSIVE lock for the whole operation. REPACK does the same job (and can reorder rows to match an index), and with CONCURRENTLY it does it without cutting off traffic. The two old commands remain for compatibility.

sql
-- Rewrite the table following its previous clustering index, without blocking
REPACK (CONCURRENTLY) orders USING INDEX;

Stable plans with pg_plan_advice and pg_stash_advice. The classic "this query was fine yesterday, today the planner picked a different plan" incident finally has an answer inside PostgreSQL itself. pg_plan_advice lets you pin or experiment with planner choices through a small "plan advice" language, and pg_stash_advice stores that advice and applies it automatically by query identifier. In other words, you can fix a slow plan without shipping new code.

Read on the replica what you just wrote. Anyone routing reads to standbys knows the bug: a user saves a change and the next request doesn't show it because the replica is a few milliseconds behind. The new WAIT FOR LSN handles that read-your-writes pattern: the app keeps the WAL position after writing to the primary and, before reading from the standby, waits until it has been replayed there.

sql
-- On the primary, right after the write
SELECT pg_current_wal_insert_lsn();   -- e.g. 0/0306EE20

-- On the standby, before reading; without TIMEOUT it would wait forever
WAIT FOR LSN '0/0306EE20' WITH (TIMEOUT '100ms', NO_THROW);

With NO_THROW it returns success or timeout instead of raising an error, so the application can decide whether to retry or fall back to the primary.

Logical replication without a restart. Creating the first logical replication slot now raises the effective WAL level to logical automatically when it was set to replica; effective_wal_level shows the value in use. Sequences are finally replicated too (CREATE PUBLICATION ... FOR ALL SEQUENCES), which removes a long-standing pain point in logical-replication migrations.

Faster without changing anything. Foreign key checks are quicker (bulk inserts were nearly 2x faster in the project's testing), NOT IN becomes an anti-join when no NULLs are present, and autovacuum processes indexes with parallel workers and ranks tables with a scoring system you can inspect in pg_stat_autovacuum_scores. Developers get niceties such as INSERT ... ON CONFLICT DO SELECT, which returns the existing row and saves the extra round trip in "get or create", plus JSON output for COPY.

What can break

The incompatibility list is long; these are the items most likely to bite:

  • JIT is off by default. Its cost estimates proved unreliable. If you run heavy analytical queries, benchmark before and after and turn it back on if you miss it.
  • max_locks_per_transaction goes from 64 to 128, but lock memory is sized differently now: if you had tuned it, double your value to keep the same capacity.
  • io_workers is gone, replaced by settings including io_min_workers and io_max_workers, which scale I/O workers automatically. Any postgresql.conf that sets io_workers needs attention.
  • RADIUS is removed, and every md5 password login now logs a warning (md5 was deprecated in 18). Time to move to SCRAM.
  • standard_conforming_strings is always on. Dumps made by an older pg_dump with that setting off won't load correctly: take the dump with the 19 pg_dump.
  • pg_upgrade refuses clusters with btree_gist indexes on inet/cidr (they could drop rows that should match) or database, role or tablespace names containing line breaks.
  • Reindex after upgrading full text search and pg_trgm indexes in databases using the ICU or builtin locale provider, because character classification changes.
  • Monitoring: sync_error_count becomes sync_table_error_count in pg_stat_subscription_stats, and several buffer wait events were renamed. Check your dashboards and alerts.

How to upgrade to PostgreSQL 19

It's a major release, so you need pg_dumpall, pg_upgrade or logical replication. With pg_upgrade, always run the new version's binary and start with --check, which validates both clusters without touching data (paths follow a Debian/Ubuntu package install):

bash
# With both servers stopped, as the postgres user
/usr/lib/postgresql/19/bin/pg_upgrade \
  --old-bindir=/usr/lib/postgresql/18/bin \
  --new-bindir=/usr/lib/postgresql/19/bin \
  --old-datadir=/var/lib/postgresql/18/main \
  --new-datadir=/var/lib/postgresql/19/main \
  --jobs=4 --check

# If the check passes, run it again without --check (add --link to avoid copying files)

--link skips copying files and is much faster, but once you start the new cluster you can't go back to the old one. After the upgrade, the docs ask you to regenerate statistics:

bash
vacuumdb --all --analyze-in-stages --missing-stats-only --jobs=4
vacuumdb --all --analyze-only --jobs=4

For containers, the official image already publishes postgres:19, postgres:19-trixie and postgres:19-alpine. Bumping the image tag doesn't migrate an 18 data directory, though: you still need pg_upgrade or a dump.

Pre-production checklist

  1. Run pg_upgrade --check against a copy of the real cluster and fix whatever it flags.
  2. Search postgresql.conf for io_workers and max_locks_per_transaction, and pg_hba.conf for RADIUS or md5.
  3. Time your analytical queries with and without JIT before accepting the new default.
  4. Update dashboards that read pg_stat_subscription_stats or buffer wait events.
  5. If you use ICU or builtin locales with text search or pg_trgm, schedule the REINDEX inside the window.
  6. Try REPACK (CONCURRENTLY) on a genuinely bloated table in staging before retiring your VACUUM FULL scripts.

My take: REPACK (CONCURRENTLY) and pg_stash_advice go after two of the problems that cause the most PostgreSQL pages: maintenance that blocks and plans that change without warning. That makes 19 worth testing now, even if production waits for the first minor release.

Sources

Jorge Turbica

Software Engineer and SRE. I write about the real challenges I run into in production.

See portfolio ↗