What Changes for Your SQL in PostgreSQL 19: Constraints, Full-Text Search, Query Plans, and Disabling JITNote · digest for December 3
Modern editorial vector poster: a fork in the road on the upgrade to PostgreSQL 19 where legacy SQL queries meet warning markers for changed plans and rules.
Note3 sections≈ 5 min

What Changes for Your SQL in PostgreSQL 19: Constraints, Full-Text Search, Query Plans, and Disabling JIT

Before a major PostgreSQL upgrade, you have two choices: run pg_upgrade and hope your standard SQL doesn't flinch, or diff your queries across both versions ahead of time. While updating The Art of PostgreSQL, Dimitri Fontaine took the second path—comparing outputs on 18.6 against PostgreSQL 19 (19.0 shipped November 19, 2026). His breakdown of 18.6 vs 19.0 surfaced 11 changes that hit existing SQL directly.

Planner reads the schema: NOT NULL vs CHECK and eager aggregation

PostgreSQL 19's planner leans heavily on NOT NULL metadata in the system catalog. Previously, NOT IN (SELECT ...) produced a hashed SubPlan, forcing you to write NOT EXISTS for an Anti Join. In 19.0, the planner builds a Hash Right Anti Join automatically whenever NULL is impossible on both sides. The same applies to LEFT JOIN ... WHERE r.col IS NULL: filtering IS NULL on any NOT NULL column of the right table now triggers the optimization.

For years, teams added CHECK (col IS NOT NULL) NOT VALID + VALIDATE CONSTRAINT on large tables to avoid long locks. They look equivalent. In 19.0, however, the planner ignores CHECK and sticks with hashed SubPlan—only a real NOT NULL constraint unlocks the speedup (and since PG 18, real NOT NULL can also be added without downtime):

-- In 19.0, produces Hash Right Anti Join when driverid is NOT NULL
EXPLAIN (COSTS OFF)
SELECT surname FROM f1db.drivers d
 WHERE driverid NOT IN (
   SELECT driverid FROM f1db.results r WHERE r.position = 1
 );

-- Real NOT NULL without a long table lock (available since PG 18)
ALTER TABLE t ADD CONSTRAINT c_nn NOT NULL my_col NOT VALID;
ALTER TABLE t VALIDATE CONSTRAINT c_nn;

NOT NULL also simplifies IS DISTINCT FROM, COALESCE(), and IS TRUE/FALSE, though NOT EXISTS stays safer since a single NULL in NOT IN empties the entire result. Eager aggregation (enable_eager_aggregate = on) also arrived: Partial HashAggregate collapses rows before JOIN even without parallelism (on f1db.results with 26,576 rows, Postgres now groups by constructorid first, then joins).

Silent traps: random() shadowing, search drift, and syntax tweaks

pg_catalog gained random(date, date), random(timestamp, timestamp), and random(timestamptz, timestamptz). Because the system schema is searched before public, any custom function with the same signature will silently stop being called. You can check for collisions on a 19.0 test instance right away:

-- Find custom functions shadowed by pg_catalog in PG 19
SELECT p.oid::regprocedure AS shadowed
  FROM pg_proc p
 WHERE p.pronamespace NOT IN (
         'pg_catalog'::regnamespace, 'information_schema'::regnamespace
       )
   AND EXISTS (
         SELECT 1 FROM pg_proc c
          WHERE c.pronamespace = 'pg_catalog'::regnamespace
            AND c.proname = p.proname AND c.proargtypes = p.proargtypes
       );

If that returns rows, rename your functions or schema-qualify calls before logic quietly diverges.

The second silent minefield is full-text search (tsvector) and pg_trgm. Character classification switched from libc (LC_CTYPE) to the database locale provider (ICU or builtin C.UTF-8). Snowball stemmers updated too: Dutch switched algorithms (the old one is now dutch_porter), and eight other languages—including English, German, and French—stem certain words differently. Stored tsvector columns keep old stems while to_tsquery() generates new ones, causing searches to silently miss rows until you reindex and recompute.

Small syntax shifts: json_array() on an empty subquery now returns [] instead of NULL, and standard_conforming_strings is permanently locked to on (re-dump old off backups using pg_dump 19). If you tested betas, seven features didn't make 19.0—including GROUP BY ALL, SQL/PGQ, and FOR PORTION OF.

JIT disabled by default and migration checks

For the first time since v12, jit (on-the-fly LLVM SQL compilation) is off by default. jit_above_cost estimates misfired too often: as a table grew, a fast query would suddenly cross the threshold, pay LLVM compilation overhead, and tank in latency. OLTP services lose those spikes automatically; for analytics roles, turn JIT back on selectively:

-- Re-enable JIT only for the analytics role
ALTER ROLE reporting IN DATABASE f1db SET jit = on;
ALTER ROLE reporting IN DATABASE f1db SET work_mem = '256MB';

Subplans in EXPLAIN also got descriptive names (SubPlan any_1, InitPlan expr_2 instead of SubPlan 1), so check any plan parsers. log_lock_waits now defaults to on, and after pg_upgrade remember to run vacuumdb --all --analyze-only to refresh autovacuum stats.

Pre-upgrade checklist for PG 19

  • Replace CHECK (col IS NOT NULL) with real NOT NULL (NOT VALID + VALIDATE).
  • Run the pg_proc check for random(...) shadowing.
  • Rebuild FTS/pg_trgm indexes (REINDEX CONCURRENTLY) and recompute stored tsvector columns.
  • Enable jit = on for analytics roles, and check EXPLAIN parsers and json_array() callers.
Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 3