PostgreSQL 19 Linux Guide: REPACK, pg_plan_advice & Upgrade
This deep-dive covers postgresql 19 linux with actionable analysis, practical implications, and expert insights.
Quick answer: Install or upgrade PostgreSQL 19 Linux servers from the official PGDG repository (postgresql-19), reclaim table bloat online with REPACK (CONCURRENTLY), lock regression-prone query plans using pg_plan_advice and pg_stash_advice, and enforce read-your-writes standby consistency with WAIT FOR LSN.
Released on November 19, 2026, PostgreSQL 19 adds three core operational upgrades for Linux database administrators. Native REPACK replaces trigger-based bloat tools like pg_repack, pg_plan_advice enables plan pinning in core contrib modules, and logical decoding can now activate under wal_level = replica without a restart.
Whether you scale JSON workloads from our PostgreSQL vs MySQL JSONB performance comparison or store vectors for a production RAG agent with pgvector on Ubuntu, PostgreSQL 19 reduces downtime and simplifies query tuning.
What Changed in PostgreSQL 19 for Linux Operations
Compare key operational changes between PostgreSQL 18 and PostgreSQL 19 before upgrading Ubuntu 24.04 LTS or Debian servers:
| Capability | PostgreSQL 18 Behavior | PostgreSQL 19 Behavior |
|---|---|---|
| Online bloat cleanup | Requires VACUUM FULL (table lock) or external pg_repack |
Built-in REPACK (CONCURRENTLY) using logical decoding |
| Query plan pinning | External extensions or query rewrites required | Core contrib modules pg_plan_advice and pg_stash_advice |
| Standby read consistency | Application polling of pg_last_wal_replay_lsn() |
Native WAIT FOR LSN command with modes and timeouts |
| Logical decoding activation | Requires wal_level = logical and server restart |
Can activate dynamically under wal_level = replica |
| JIT default and lock capacity | jit = on, max_locks_per_transaction = 64 |
jit = off by default, max_locks_per_transaction = 128 |
PostgreSQL 19 also removes legacy RADIUS authentication, disables standard_conforming_strings = off, emits warnings for deprecated MD5 password logins via md5_password_warnings, and replaces the single io_workers parameter with dedicated I/O worker settings.
Step 1: Install PostgreSQL 19 Linux Packages via PGDG
Ubuntu and Debian base repositories freeze older PostgreSQL releases, so configure the official PostgreSQL Global Development Group (PGDG) repository first. The postgresql-common package ships an automated setup script that installs the archive keyring and APT sources for your distribution codename.
sudo apt update
sudo apt install -y postgresql-common ca-certificates
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo apt update
sudo apt install -y postgresql-19 postgresql-client-19 postgresql-contrib-19
Verify that the new cluster is active and check its port assignment with pg_lsclusters. Installing version 19 alongside an existing PostgreSQL 17 or 18 cluster leaves the older service on port 5432 and binds the fresh PostgreSQL 19 cluster to port 5433 until you migrate.
sudo pg_lsclusters
psql -U postgres -p 5433 -c "SELECT version();"
Pair your database host configuration with strict OS isolation by following our guide on hardening systemd services with sandboxing on Linux and maintaining off-box encrypted snapshots as detailed in automating server backups with Restic and systemd timers.
Step 2: Upgrade an Existing Cluster Safely with pg_upgrade
Every major PostgreSQL upgrade changes internal catalog and storage structures, so back up your cluster before running pg_upgrade. Also verify two PostgreSQL 19 pre-upgrade checks: remove any carriage returns or line feeds in database, role, or tablespace names, and drop or rebuild any legacy btree_gist indexes on inet or cidr columns because PostgreSQL 19 blocks upgrading clusters that contain them.
sudo systemctl stop postgresql
sudo -u postgres /usr/lib/postgresql/19/bin/pg_upgrade --old-datadir=/var/lib/postgresql/18/main --new-datadir=/var/lib/postgresql/19/main --old-bindir=/usr/lib/postgresql/18/bin --new-bindir=/usr/lib/postgresql/19/bin --link --check
The --link flag creates hard links instead of copying data files byte-for-byte, cutting upgrade time on multi-terabyte NVMe volumes to seconds. Once --check passes cleanly, rerun the command without --check, switch the port back to 5432 in /etc/postgresql/19/main/postgresql.conf, start the service, and refresh optimizer statistics:
sudo -u postgres /usr/lib/postgresql/19/bin/pg_upgrade --old-datadir=/var/lib/postgresql/18/main --new-datadir=/var/lib/postgresql/19/main --old-bindir=/usr/lib/postgresql/18/bin --new-bindir=/usr/lib/postgresql/19/bin --link
sudo systemctl start postgresql@19-main
sudo -u postgres vacuumdb --all --analyze-in-stages
Step 3: Reclaim Table Bloat Online with REPACK (CONCURRENTLY)
Heavy update and delete workloads leave bloated heap pages that standard VACUUM marks reusable without shrinking file size on disk. In PostgreSQL 19, the new REPACK SQL command rewrites the table and its indexes into compact files and returns unused blocks to the Linux filesystem.
Adding CONCURRENTLY avoids holding an ACCESS EXCLUSIVE lock for the entire rewrite. Instead, PostgreSQL holds a SHARE UPDATE EXCLUSIVE lock during the copy, captures concurrent inserts, updates, and deletes via a logical replication slot controlled by max_repack_replication_slots, and takes a brief ACCESS EXCLUSIVE lock only at the final file swap.
REPACK (CONCURRENTLY, VERBOSE, ANALYZE) public.events;
REPACK (CONCURRENTLY, VERBOSE) public.orders USING INDEX idx_orders_created_at;
SELECT pid, datname, relid::regclass, phase, tuples_processed
FROM pg_stat_progress_repack;
Keep four operational constraints in mind when scheduling REPACK (CONCURRENTLY):
- Primary key or replica identity required: Target tables need a primary key or index-based
REPLICA IDENTITYforCONCURRENTLY. - Not for partitioned or unlogged tables: Concurrent mode rejects partitioned tables, materialized views, and
UNLOGGEDtables. RunREPACKon leaf partitions or offline during maintenance windows. - Long-running snapshot caveat: Concurrent repacking is not MVCC-safe for transactions using snapshots taken before
REPACKstarted, which can see the swapped table as empty after commit. - Do not use for XID wraparound: Because
REPACKrewrites the table and all indexes, standardVACUUMremains faster and safer under wraparound pressure.
Step 4: Pin Regression-Prone Plans with pg_plan_advice and pg_stash_advice
PostgreSQL 19 ships pg_plan_advice and pg_stash_advice in the standard contrib package so DBAs can stabilize sudden query plan regressions without modifying application code. Both modules operate during query planning and manage shared memory, so load them at startup in /etc/postgresql/19/main/postgresql.conf:
shared_preload_libraries = 'pg_plan_advice,pg_stash_advice'
compute_query_id = 'auto'
pg_stash_advice.persist = on
After restarting PostgreSQL 19, create the extensions in your target database and run EXPLAIN (COSTS OFF, PLAN_ADVICE, VERBOSE) on the slow query. The VERBOSE flag prints the Query Identifier, while PLAN_ADVICE outputs the exact advice string describing the chosen join order, join strategy, scan methods, and parallelism.
CREATE EXTENSION IF NOT EXISTS pg_plan_advice;
CREATE EXTENSION IF NOT EXISTS pg_stash_advice;
EXPLAIN (COSTS OFF, PLAN_ADVICE, VERBOSE)
SELECT o.id, c.region
FROM orders o
JOIN customers c ON o.customer_id = c.id
WHERE c.region = 'eu-west';
Instead of pasting the full generated advice string, trim it down to only the constraint you need, test it in your session with pg_plan_advice.advice, and then persist it to a named shared-memory stash keyed by the query ID:
SET pg_plan_advice.advice = 'JOIN_ORDER(c o) INDEX_SCAN(o idx_orders_customer_id)';
SELECT pg_create_advice_stash('prod_hotfix');
SELECT pg_set_stashed_advice(
'prod_hotfix',
-4819203847123456789::bigint,
'JOIN_ORDER(c o) INDEX_SCAN(o idx_orders_customer_id)'
);
ALTER DATABASE app_prod SET pg_stash_advice.stash_name = 'prod_hotfix';
Look for /* matched */ next to the supplied advice in EXPLAIN output to confirm enforcement. Note that pg_plan_advice cannot force plans the optimizer considers invalid or control aggregation and set-operation strategies such as UNION.
Step 5: Enforce Standby Read-Your-Writes with WAIT FOR LSN
Applications offloading reads to streaming replicas often hit stale-read race conditions right after a primary write. PostgreSQL 19 adds the native WAIT FOR LSN command so a standby session pauses until WAL replay catches up to the primary's commit LSN.
/* Run on the primary after commit to capture current LSN */
SELECT pg_current_wal_flush_lsn();
/* Run on the standby before reading recent writes */
WAIT FOR LSN '0/4A2B180' WITH (MODE 'standby_replay', TIMEOUT '2s', NO_THROW);
Passing NO_THROW returns a clean status string (success, timeout, or not in recovery) instead of raising an SQL exception, allowing application connection pools to fall back cleanly to the primary if a replica lags past your latency budget.
Troubleshooting PostgreSQL 19 Upgrades and New Features
pg_upgradefails onbtree_gistindexes: Drop or recreateinetandcidrindexes using standard GiST opclasses on the old cluster before runningpg_upgrade, as legacybtree_gistopclasses for network types are rejected in version 19.REPACK (CONCURRENTLY)refuses to start: CheckSELECT indexrelid::regclass FROM pg_index WHERE indisvalid = false;and drop or reindex invalid indexes first. Also verifymax_repack_replication_slotshas headroom and that the table is not partitioned or missing a replica identity index.- Stashed plan advice does not apply to prepared statements: Prepared plans cached before updating the stash ignore new advice until replanned. Enable
pg_plan_advice.always_store_advice_details = onin debugging sessions when inspectingEXPLAIN EXECUTEoutput. - Client logins log MD5 deprecation warnings: Upgrade legacy roles from MD5 to
scram-sha-256withALTER ROLE app_user WITH PASSWORD '...';after settingpassword_encryption = 'scram-sha-256', or temporarily mute log noise withmd5_password_warnings = offduring migration.
All terminal commands, code snippets, and configuration parameters in this guide were verified in our testing environment before publication. Adjust configuration paths to match your specific distribution.
Was this technical analysis helpful?
Your feedback informs our benchmark updates and ongoing article audits.
FAQ
Frequently Asked Questions
Structured for search engines and AI answer systems (AEO/GEO).
VACUUM FULL holds an ACCESS EXCLUSIVE lock for the entire table rewrite, blocking all reads and writes. REPACK (CONCURRENTLY) uses a SHARE UPDATE EXCLUSIVE lock and logical decoding to capture concurrent changes, holding an ACCESS EXCLUSIVE lock only briefly during the final file swap.
REPACK (CONCURRENTLY) requires a primary key or index-based REPLICA IDENTITY, cannot run inside a transaction block, and does not support partitioned tables, UNLOGGED tables, materialized views, or tables with invalid indexes.
Add pg_plan_advice,pg_stash_advice to shared_preload_libraries in postgresql.conf, restart the cluster, run CREATE EXTENSION pg_stash_advice, stash advice by query ID with pg_set_stashed_advice, and set pg_stash_advice.stash_name.
Yes. When wal_level is set to replica, PostgreSQL 19 can activate logical decoding dynamically without requiring a server restart.
More answers in our FAQ hub.
Newsletter
Practical Linux & Applied AI Newsletter
Get new tested tutorials and benchmark comparisons delivered directly to your inbox. Zero spam.
Join Weekly guides readers getting our weekly digest.
- Practical Linux administration & terminal workflows
- Tested open-source AI setups & benchmarks
- Zero spam - unsubscribe anytime