Hacker News PostgreSQL· rgoomar·· 7d ago
What Changes When You Upgrade from PostgreSQL 18 to 19
What Changes When You Upgrade from PostgreSQL 18 to 19
Key Takeaway
In PostgreSQL 18.6 vs 19.0 tests, median time fell from 202.0 to 119.0 ms for a 100,000-row foreign-key insert and from 51.1 to 38.6 ms for NOT IN counting 250,000 missing IDs. Native REPACK (CONCURRENTLY) allows reads and writes during the rewrite but needs an ACCESS EXCLUSIVE lock for the final swap.
Why It Matters
Native concurrent REPACK can replace some scheduled pg_repack jobs, but the decision depends on how long the final swap waits for an exclusive lock under production traffic.
Technical Breakdown · Distilled from the original source
Foreign Key Inserts and Anti Joins
- A single Docker client warmed each test twice and took the median of seven runs on 18.6 and 19.0. The 100,000-row insert without a foreign key fell from 47.3 ms to 45.4 ms. Subtracting that baseline puts the estimated foreign key overhead at about 155 ms versus 74 ms. Parent keys were already in memory; disk reads were not tested.
- Version 19 can check the parent's unique index directly, except for partitioned parents and range-based temporal foreign keys. With both ID columns declared
NOT NULL,NOT INswitched from a hashed subplan filter to a hash anti join. The rewrite does not apply if either side can containNULL.
Concurrent Rewrites and Plan Debugging
REPACK (CONCURRENTLY)requires a regular logged table with a primary key or replica identity index, execution outside a transaction block, and room for another copy of the table and indexes. For partitioned tables, target an eligible leaf. The final swap still needs anACCESS EXCLUSIVElock. The test retained all 2,353 rows while shrinking total size from 1,504 kB to 656 kB. Native REPACK cannot move the table to another tablespace.pg_plan_adviceexposes and tests plan advice within a session.pg_stash_adviceattaches advice by query ID and affects future planning, not cached plans.
Insert Results and Replica Reads
ON CONFLICT DO SELECT RETURNING idreturns the inserted or existing ID in one round trip, but the conflict check can still consume a sequence value.- After committing on the primary, capture a WAL LSN and use
WAIT FOR LSNon the physical standby. Read there after success and fall back to the primary on timeout. Before upgrading, runpg_upgrade --checkon a restored copy and review the removal ofio_workersand the new default of disabled JIT.
Source: Hacker News PostgreSQL· rishigoomar.com
PG Radar summarizes verified changes and impact. Read the original post for full technical details and code samples.