The PostgreSQL 19 announcement says the release “improves the performance of foreign key checks, which in testing made bulk inserts nearly 2x faster”. I wanted to know how that holds up outside the project’s own testing, so I ran Postgres 18.7 and 19.0 side by side on one server and measured that claim plus four other changes from the release notes.
Everything below comes from one run of the scripts linked at the end. Medians are shown; the raw per-run values are in the results archive.
Setup
| Part | Value |
|---|---|
| Server | DigitalOcean dedicated droplet c-8: 8 vCPU, 16 GB RAM |
| Images | postgres:18.7 and postgres:19.0 (official Docker images) |
| Settings | Same on both: shared_buffers=2GB, maintenance_work_mem=1GB, max_wal_size=16GB, checkpoint_timeout=30min, jit=off |
| Autovacuum | Off during the tests (set with ALTER SYSTEM), on only for the autovacuum test |
| Runs | Inserts and queries 5 runs, maintenance tests 3 runs, median reported |
JIT is off on both because Postgres 19 turns it off by default. Leaving it on for 18 would have mixed a second change into every query.
One gotcha while building this: passing -c autovacuum=off on the command line overrides anything you later set with ALTER SYSTEM, so autovacuum could never be switched back on for the autovacuum test. The script sets it through ALTER SYSTEM instead.
1. Foreign key checks
A foreign key from child.parent_id to parent.id means every inserted child row needs a lookup in the parent’s primary key index, plus a FOR KEY SHARE row lock on the parent row so it can’t be deleted mid-insert. That is one extra index lookup per row.
The test: a parent table with 1,000,000 rows and a child table that receives 5,000,000 rows, loaded two ways.
-- INSERT … SELECT
insert into child(parent_id, payload)
select (i % 1000000) + 1, md5(i::text) from generate_series(1, 5000000) i;
-- COPY from a CSV with the same rows
copy child(parent_id, payload) from '/tmp/child.csv' (format csv);
| Load (5M rows) | 18.7 | 19.0 | Speed-up |
|---|---|---|---|
| COPY, with FK | 31.45 s | 15.19 s | 2.07× |
| INSERT … SELECT, with FK | 37.62 s | 21.45 s | 1.75× |
| COPY, no FK | 3.67 s | 3.35 s | 1.09× |
| INSERT … SELECT, no FK | 9.99 s | 9.69 s | 1.03× |
The claim holds for COPY into a table with a foreign key. Without the foreign key the two versions are within 3–9 %, so the gain really is in the FK check. On 18.7, the foreign key turned a 3.7 s COPY into 31.5 s; 19.0 removes more than half of that extra time.
Single-row inserts
Most applications don’t bulk load; they insert one row per request. pgbench with 16 clients ran this script for 60 seconds against the table with the foreign key:
\set p random(1, 1000000)
insert into child(parent_id, payload) values (:p, md5(:p::text));
| pgbench, 16 clients, 60 s | 18.7 | 19.0 |
|---|---|---|
| With FK | 30,375 tps | 32,940 tps (+8 %) |
| Without FK | 35,474 tps | 36,082 tps (+2 %) |
Here the gain is 8 %, not 2×.
2. NOT IN becomes an anti join
Release note: “Allow NOT IN clauses to be converted to more efficient ANTI JOINs when NULLs are not present.”
create table a(x int not null); -- 5,000,000 rows
create table b(y int not null); -- 1,000,000 rows (and a second case with 100,000)
select count(*) from a where x not in (select y from b);
An anti join hashes b once and probes it with each row of a. Postgres 18 never rewrites NOT IN that way, because a single NULL in b makes NOT IN return no rows at all, and an anti join would return rows. Postgres 18 can still hash the subquery when it fits in work_mem; when it doesn’t, it falls back to a materialized subplan and rescans it for every row of a.
The plans from the test server:
-- 18.7, b = 1,000,000 rows
Filter: (NOT (ANY (x = (SubPlan 1).col1)))
SubPlan 1
-> Materialize
-> Seq Scan on b
-- 19.0, same query
-> Parallel Hash Anti Join
Hash Cond: (a.x = b.y)
| NOT IN | 18.7 | 19.0 |
|---|---|---|
| b = 1,000,000 rows | did not finish in 120 s (5 of 5 runs) | 0.54 s |
| b = 100,000 rows | 343 ms | 280 ms |
With the small b, 18.7 already hashes the subquery and the difference is small. With the large one, 18.7 hit the 120 s statement_timeout in every run. Both columns are declared NOT NULL, which is what lets 19 do the rewrite. If the columns are nullable, writing the query as NOT EXISTS is still the way to get an anti join.
3. Bloat: VACUUM FULL, REPACK and REPACK CONCURRENTLY
Postgres never updates a row in place; an update writes a new version and the old one stays until no running query can see it. VACUUM marks that space as reusable but doesn’t shrink the file. To give space back to the operating system the table has to be rewritten.
The test table: 5,000,000 rows with a 200-byte note, then 80 % deleted and vacuumed. It still took 1.35 GB. While each rewrite ran, pgbench sent about 18,000 transactions per second of single-row updates and reads (8 clients, -P 1 for per-second numbers).
| Command | Version | Time | Size after | Lowest 1-second tps during the command |
|---|---|---|---|---|
| VACUUM FULL | 18.7 | 2.35 s | 279 MB | 0 |
| VACUUM FULL | 19.0 | 1.72 s | 279 MB | 460 |
| REPACK | 19.0 | 1.77 s | 279 MB | 380 |
| REPACK (CONCURRENTLY) | 19.0 | 2.16 s | 280 MB | 12,533 |
VACUUM FULL and plain REPACK hold an ACCESS EXCLUSIVE lock for the whole rewrite, so traffic stops on both versions. The lowest one-second value depends on how the roughly two-second lock lines up with pgbench’s one-second buckets, so I don’t read the 0 vs 460 as a real difference.
REPACK (CONCURRENTLY) copies the table while reads and writes continue, captures the changes made during the copy with logical decoding (the same machinery logical replication uses), applies them to the new copy, and takes the exclusive lock only for the short file swap at the end. The table needs a primary key. In this test it took 0.4 s longer than VACUUM FULL, and the slowest second still did 12,533 transactions, about two thirds of normal.
4. Parallel autovacuum
Postgres 19 lets autovacuum vacuum indexes with parallel workers, controlled by autovacuum_max_parallel_workers and the per-table storage parameter autovacuum_parallel_workers.
The test table has 5,000,000 rows, 8 indexes and half its rows deleted. Elapsed time comes from the autovacuum log line (log_autovacuum_min_duration = 0):
automatic vacuum of table "postgres.public.wide": index scans: 1
parallel workers: index vacuum: 4 planned, 4 launched in total
system usage: CPU: user: 0.80 s, system: 0.12 s, elapsed: 33.90 s
| Autovacuum, 8 indexes | Median |
|---|---|
| 18.7 | 36.3 s |
| 19.0, no parallel workers | 35.7 s |
| 19.0, 4 parallel workers | 33.9 s |
Four workers saved about 5 % on this table. Only the index vacuuming runs in parallel.
5. TOAST: lz4 by default
default_toast_compression now defaults to lz4 instead of pglz. 50,000 rows with a 200-object jsonb document each:
| 18.7 | 19.0 | |
|---|---|---|
pg_column_compression(body) | pglz (all rows) | lz4 (all rows) |
pg_total_relation_size('docs') | 416,899,072 bytes | 416,899,072 bytes |
Both versions came out at exactly the same size on this data. I didn’t measure compression or decompression speed.
New SQL
Two additions from the release notes that are easy to try:
insert into u values (2, 'a@x') on conflict (email) do select returning *;
copy (select * from u) to stdout (format json);
ON CONFLICT DO SELECT returns the conflicting row instead of doing nothing, and COPY TO can write JSON. Neither syntax exists in 18.
Before you upgrade
Two changes in the “Migration to Version 19” section can break an existing setup:
- JIT is disabled by default. If you run long analytic queries that relied on it, set
jit = onagain. io_workersis removed. It was replaced byio_min_workers,io_max_workers,io_worker_idle_timeoutandio_worker_launch_interval. A config that still setsio_workerswill not start.
What this test doesn’t cover
One server size, one run of the suite, Docker on a single droplet. I didn’t test replication, pg_plan_advice, other NOT IN shapes, compression speed, or a bigger machine.
Scripts and raw results
Everything is also in the postgres-18-vs-19/ folder of the db-wars repo.
bench.sh: every test above for one Postgres image tag (bash bench.sh 19.0 out)run-on-digitalocean.sh: creates the droplet, runsbench.shfor 18.7 and 19.0, copies the results back and deletes the droplet (needsDO_TOKENandREGION)results.tar.gz: per-run JSON lines for both versions, theEXPLAINplans, pgbench per-second logs, autovacuum log lines, non-default settings andselect version()output