PostgreSQL 19 came out on November 19. This post covers four changes a small team will notice first, REPACK (CONCURRENTLY), the pg_plan_advice and pg_stash_advice extensions, WAIT FOR LSN, and INSERT ... ON CONFLICT DO SELECT, plus a table of compatibility changes to check before upgrading.
The PostgreSQL Global Development Group released PostgreSQL 19 on November 19. The announcement sums up the release as simpler administration and simpler development. This post picks four changes from the announcement and the release notes that a small team will notice first.
REPACK (CONCURRENTLY)reclaims unused table space without blocking reads or writes.pg_plan_adviceandpg_stash_advicelet you fix a query whose plan changed and got slower, without changing the application.WAIT FOR LSNmakes a standby wait until it can read the data you just wrote.INSERT ... ON CONFLICT DO SELECTdoes "get or create" in one statement.
Image: devs7udio, four changes picked from the PostgreSQL 19 announcement
Tables that get many updates and deletes build up unused space. The announcement calls it bloat and says it can also hurt query performance significantly. Until now the tools were VACUUM FULL and CLUSTER, and both blocked access to the table until they finished.
REPACK in PostgreSQL 19 reclaims that space and can reorder a table's data to match an index. REPACK (CONCURRENTLY) does the same without blocking reads or writes. REPACK replaces VACUUM FULL and CLUSTER, and both stay available for compatibility. The release notes say the two commands did similar things under confusing names, so they were unified.
The REPACK documentation also lists how CONCURRENTLY works and where it cannot be used.
- Most of the work runs under a
SHARE UPDATE EXCLUSIVElock. AnACCESS EXCLUSIVElock is taken only in the final phase that swaps the files. Changes made in the meantime are captured with logical decoding and applied. - It cannot be used on partitioned tables,
UNLOGGEDtables or materialized views. The same goes for a table with no primary key and no index-based replica identity. - It cannot run inside a transaction block, and it needs room for one more replication slot. The new
max_repack_replication_slotssetting sets that limit. - It might fail to complete if other transactions run DDL on the table.
Progress shows up in the new pg_stat_progress_repack system view.
The PostgreSQL query planner usually picks an efficient plan, but the plan can change as the data changes, and sometimes the new plan is slower. PostgreSQL 19 adds two extensions for this.
pg_plan_advicestabilizes plan choices and lets you try different plans with a small "plan advice" language. ThePLAN_ADVICEoption ofEXPLAINshows the chosen plan as an advice string, and putting that string in thepg_plan_advice.advicesetting makes the planner take the same choices again.pg_stash_advicestores advice and applies it automatically to queries with a matching query identifier. This is the part behind the announcement's "fix a slow plan without changing your application".
- The data distribution changes → The planner picks another plan
- The planner picks another plan → The query gets slower
- The query gets slower → EXPLAIN (PLAN_ADVICE)
- EXPLAIN (PLAN_ADVICE) → pg_stash_advice
- pg_stash_advice → Applied automatically to that query
Both documents are direct about the limits.
- The planner adjusting plans as data changes is normally an advantage. If advice prevents that, a very poor plan may be chosen, so the documentation says to use it only where and as much as needed.
- Advice only chooses among plans the planner considers viable. It cannot force a plan the planner refused to consider.
- Aggregation and set operations such as
UNIONcannot be controlled with advice yet. - Advice is consulted only when a query is planned. It does not affect plans that are already cached.
pg_stash_advicehas no sophisticated security model yet. The documentation says to assume that the contents of stashed advice strings may become visible to non-privileged users.
Applications that send reads to standbys share an old problem. A read on the standby right after a write on the primary may not see that write yet. WAIT FOR LSN in PostgreSQL 19 lets a session on a standby wait until the WAL has been replayed up to a specific LSN before it runs a query. An LSN is a position in the WAL.
Image: devs7udio, the order of steps with WAIT FOR LSN
According to the WAIT documentation, the command waits indefinitely when no timeout is given. The default mode is standby_replay, which waits for replay, and other modes wait only for the WAL to be written or flushed to disk. With NO_THROW, a timeout comes back as a status string, not an error.
Logical replication is also easier to start. Enabling it often required a server restart before. When wal_level is replica, PostgreSQL 19 raises the effective WAL level to logical automatically once you create the first logical replication slot. The new effective_wal_level setting shows the level in use. Sequence values can now be replicated logically too, published with FOR ALL SEQUENCES in CREATE PUBLICATION.
"Get it if it exists, create it if it does not" is a common pattern. It used to take a separate INSERT and SELECT, or a DO UPDATE that changes nothing. INSERT ... ON CONFLICT DO SELECT in PostgreSQL 19 returns the existing conflicting row through RETURNING. The announcement says it saves a network round trip.
The INSERT documentation sets three conditions. A RETURNING clause is required, a conflict target (conflict_target) must be given, and you need SELECT privilege on the table. Adding FOR UPDATE or FOR SHARE also locks the returned row.
The announcement lists smaller additions as well.
COPYcan output JSON. With theFORCE_ARRAYoption the output is a single JSON array.- The SQL/JSON path language gains string methods such as
lower(),upper(),replace(),split_part()andbtrim(). - The window functions
lead(),lag(),first_value(),last_value()andnth_value()can skip NULL values withIGNORE NULLS. random()can also generate dates and timestamps within a range.
Some workloads get faster with no change to the application. The announcement says the performance of foreign key checks improved, which in testing made bulk inserts nearly 2x faster.
- Bulk inserts with foreign keys2x
A testing result from the PostgreSQL Global Development Group, nearly 2x
Other improvements from the same paragraph and the release notes:
NOT INclauses are converted to more efficient anti-joins when NULL values are not present.- Aggregation can run before joins, which reduces the number of rows to process.
- When
io_methodisworker, the default, the number of I/O workers adjusts automatically betweenio_min_workersandio_max_workers. - Autovacuum can vacuum indexes with parallel workers and uses a new scoring system to decide which tables go first.
- Queries that read a table can mark pages as all-visible during execution, which leaves less work for later vacuums.
LISTENandNOTIFYscale better in multi-channel workloads. Per the release notes,NOTIFYnow wakes only the backends listening to that notification.
"Migration to Version 19" in the release notes collects the changes that may break compatibility with earlier releases. Moving data from any previous release takes a dump and restore with pg_dumpall, or pg_upgrade, or logical replication. The table below carries the items a small team is most likely to hit.
| JIT disabled by default | The cost estimates that decided when to use JIT proved unreliable | Enable it yourself if you run many large analytical queries |
| RADIUS authentication removed | It was supported only over UDP, which the notes call unfixably insecure | Move to another authentication method |
| Warning after a successful MD5 login | MD5 was deprecated in PostgreSQL 18 and will be removed in a future release | Move to SCRAM. md5_password_warnings turns the warning off |
| io_workers setting removed | Four new settings replace it | Remove io_workers from your configuration |
| max_locks_per_transaction default from 64 to 128 | Lock size allocation changed, so a setting must be doubled to match its earlier capacity | Double any value you set yourself |
| standard_conforming_strings always on | Old dumps made with the setting off will not load properly | Create the dump with pg_dump from PostgreSQL 19 |
| btree_gist indexes on inet and cidr | They could exclude rows that should be returned, so the default opclass is now GiST | pg_upgrade refuses clusters with these indexes, so drop them first |
| Character classification in full text search and pg_trgm | It uses the database's locale provider, no longer libc | Reindex the affected indexes after pg_upgrade |
One more default changed. Per the announcement, when PostgreSQL is built with LZ4 support the default TOAST compression method is now lz4. The release notes also disallow carriage returns and line feeds in database, role and tablespace names, and a json_array() call that returns no rows now gives an empty JSON array where it used to give NULL.
Reading: most of the large features in this release are about not stopping a running service. Cleaning up a table, starting logical replication and fixing a query that got slower all used to need a maintenance window or a new deploy. For a small team, finding that window is a cost in itself, so these changes may matter more than the new syntax.
Reading: the order of adoption depends on how you run the database.
- A team on managed PostgreSQL waits until the provider offers 19. In the meantime, check the compatibility table against your own settings. MD5 authentication,
io_workersand analytical queries that lean on JIT come first. - A team that runs its own servers can try
REPACK (CONCURRENTLY)on a replica or a test environment first. The table needs a primary key, and there must be room for a replication slot. - Use plan advice only for the query that has a problem. As the documentation itself warns, more advice leaves the planner less room to respond to changing data.
- An application that splits reads to standbys should consider
WAIT FOR LSNtogether with a timeout. Without one it waits indefinitely.
The "nearly 2x" figure for bulk inserts is a testing result from the development group, and the conditions are not published. The announcement cannot tell you whether your own tables will see the same gain.
