Databases and servers
PostgreSQL 18 upgrade: what pg_upgrade changes and what breaks
In short
For a PostgreSQL 18 upgrade, pg_upgrade now carries most planner statistics across, runs its checks in parallel with --jobs and offers a --swap mode. The catch is initdb: version 18 turns data checksums on by default, and pg_upgrade needs both clusters to match, so an old cluster without checksums needs a new one made with --no-data-checksums.
What pg_upgrade changes in a PostgreSQL 18 upgrade
PostgreSQL 18.0 came out on 2025-09-25, and three of its release-note items are about pg_upgrade itself. The first matters most to anyone who has seen slow plans right after an upgrade: optimizer statistics are now kept through the upgrade, so the planner has numbers to work with from the first query. Extended statistics, the kind made with CREATE STATISTICS, are not kept, and neither are custom statistics from extensions or the cumulative counters. A new --no-statistics option turns the transfer off.
The second item is speed of the checks. The database checks that pg_upgrade runs before touching data can now run in parallel, controlled by the --jobs option that already existed for the copy phase.
The third is a new transfer mode, --swap, which moves the data directories into the new cluster and replaces the catalog files. The release notes call it potentially the fastest mode, and the pg_upgrade page says it can beat the other modes most clearly on clusters with many relations. Its cost is covered in the transfer mode table further down.
Statistics transfer does not remove the post-upgrade analyze step; it shortens it. The pg_upgrade page now recommends two commands after the new server starts:
vacuumdb --all --analyze-in-stages --missing-stats-only
vacuumdb --all --analyze-onlyThe data checksums mismatch, and how to avoid it
This is the change most likely to stop an upgrade cold. The initdb page for 18 says data checksums are enabled by default, and the release notes add that pg_upgrade requires matching cluster checksum settings. A 17 cluster created with the old default has no checksums, and a new 18 cluster created with the new default has them, so the pair will not upgrade.
The fix is in the same release note. Create the new cluster with initdb --no-data-checksums when the old one has none, which keeps both sides the same. The pg_upgrade instructions already say to use initdb flags compatible with the old cluster; checksums are now one of the flags that needs thought, since leaving it out no longer gives the old result.
Before you start, read the read-only data_checksums setting on the old server with SHOW data_checksums;. If it says off, the new cluster needs the opt-out flag. Turning checksums on is a separate project for later, and the initdb page notes it might carry a small performance penalty.
Choosing a pg_upgrade transfer mode in PostgreSQL 18
The mode decides two things: how long the upgrade takes and whether you can go back to the old cluster. The pg_upgrade page states the revert rules for each mode, and the table puts them side by side. Whichever mode you pick, pass the same flag to --check so the mode-specific checks run too.
With --swap, the docs recommend --sync-method=fsync, because swap leaves many garbage files in the old cluster and a syncfs pass over them takes longer. Once the file transfer step begins, the old cluster is destructively modified and is no longer safe to start, so a verified backup is a hard requirement for this mode.
| Mode | How it moves data | Old cluster afterwards | Going back |
|---|---|---|---|
| --copy (default) | Copies every file | Unmodified | Restart the old cluster |
| --link | Hard links instead of copies | Usable only if the new cluster was never started | Remove the .old suffix from global/pg_control; after a start, restore from backup |
| --clone | File cloning (reflinks) | Untouched | Restart the old cluster |
| --copy-file-range | The copy_file_range system call | Untouched | Restart the old cluster |
| --swap | Moves the data directories, replaces catalogs | Destroyed once transfer starts | Restore from backup unless pg_upgrade stopped before saying the old cluster is unsafe |
What breaks after upgrading to PostgreSQL 18
The Migration to Version 18 section of the release notes lists the behavior changes. These are the ones an application or an operator will meet, with the action each one suggests:
- MD5 passwords are deprecated. CREATE ROLE and ALTER ROLE now warn when an MD5 password is set, and the
md5_password_warningsparameter silences that. Support will be removed in a future major release. The password docs give the route: confirm client libraries support SCRAM, setpassword_encryption = 'scram-sha-256', have every user set a new password, then change pg_hba.conf to scram-sha-256. If logins fail after that edit, the page on password authentication failing after a switch to scram-sha-256 walks through the causes. - VACUUM and ANALYZE now process the inheritance children of a parent table. Jobs that ran them on a parent and expected only the parent to be touched should add
ONLY. - COPY FROM no longer treats
\.as an end-of-file marker in CSV input, and the marker must stand alone on a line. Older psql clients talking to an 18 server may hit\copyproblems, so upgrade the client tools with the server. - Unlogged partitioned tables are no longer allowed.
- AFTER triggers run as the role that was active when the trigger event was queued, which differs from the old behavior when a transaction changes role before COMMIT.
- RESTRICT foreign key violations report SQLSTATE 23001 instead of 23503. Application code that catches 23503 for these cases should also handle 23001.
- Full text search reads its files with the cluster's default collation provider. Clusters on ICU or the builtin provider should reindex full text search and pg_trgm indexes after pg_upgrade.
- Time zone abbreviations now check the session's time zone before
timezone_abbreviations.
PostgreSQL 18 pg_upgrade pre-flight checklist
Built only from the pg_upgrade page and the release notes, in the order I would work through it on 29 Nov 2026:
- Confirm the source is 9.2 or newer, and that no table column uses regcollation, regconfig, regdictionary, regnamespace, regoper, regoperator, regproc or regprocedure. pg_upgrade cannot carry those.
- Confirm you trust the old cluster's superusers. The docs warn that the upgrade runs code of their choice on the destination.
- Run initdb for 18 with flags that match the old cluster, adding
--no-data-checksumsif the old one has none. - Install the shared object files for every extension, without running CREATE EXTENSION in the new cluster.
- Run the new version's pg_upgrade with
--checkplus your chosen mode flag and--jobs, while the old server is still up. - For standbys: keep them running while the primary shuts down, compare Latest checkpoint location in every cluster, and keep
wal_levelabove minimal on the new primary. The rsync route only applies to link mode; otherwise rebuild the standbys. Old primaries before 17.0 do not copy slots to the new standby. - After the run: start the server, run the generated scripts, run the two vacuumdb commands, apply the extension update script if pg_upgrade wrote one, and reindex text search indexes if the collation note above applies.
- Delete the old cluster with the generated script only once you are satisfied.
Related notes for the PostgreSQL 18 move
Once the server is on 18, the next settings to read are the new ones for reads, covered in PostgreSQL 18 asynchronous I/O and the io_method choices. Schema changes worth planning, such as uuidv7() keys and NOT NULL constraints added without a long scan, are in the PostgreSQL 18 uuidv7 and NOT VALID post. If the database runs in containers on a single host, the note on Docker published ports and ufw is worth a read before you expose port 5432. More server notes sit on the engineering hub.
These facts were read on 29 Nov 2026. Re-check the pg_upgrade page and the newest 18.x minor release notes before the upgrade window, in case a later minor release adds its own upgrade notes. If you would rather hand the slow query work after the upgrade to someone, the database performance plan covers it.
What else do people ask?
Does pg_upgrade keep statistics in PostgreSQL 18?
Yes, most optimizer statistics are carried over unless you pass --no-statistics. Extended statistics from CREATE STATISTICS, extension statistics and the cumulative counters are not, so still run the vacuumdb analyze commands afterwards.
Why does pg_upgrade to 18 complain about checksums?
initdb in 18 enables data checksums by default and pg_upgrade needs both clusters to match. Recreate the new cluster with initdb --no-data-checksums if the old one has checksums off.
Is pg_upgrade --swap safe?
It is the fastest mode, but once the file transfer begins the old cluster is destructively modified and cannot be started. Have a tested backup, and use --sync-method=fsync as the docs recommend.
Do MD5 passwords stop working in PostgreSQL 18?
No, they still work in 18 but are deprecated, and setting one now prints a warning. The docs say support will be removed in a future major release, so moving to scram-sha-256 now is the safer plan.
Which versions can upgrade straight to PostgreSQL 18 with pg_upgrade?
The pg_upgrade page says it supports upgrades from 9.2.X and later to the current major release.
Do I need to reindex after a PostgreSQL 18 upgrade?
The release notes recommend it only for full text search and pg_trgm indexes on clusters whose default collation provider is ICU or builtin.
Sources
- PostgreSQL 18.0 release notes (migration section and pg_upgrade items), fetched 2026-11-29
- PostgreSQL 18 docs, pg_upgrade, fetched 2026-11-29
- PostgreSQL 18 released, project announcement, fetched 2026-11-29
- PostgreSQL 18 docs, initdb (data checksums), fetched 2026-11-29
- PostgreSQL 18 docs, password authentication, fetched 2026-11-29
Keep reading
Read next
- Upgrade React 18 to 19: Breaking ChangesBlog: The rest are loud, from `ReactDOM.render` to string refs and legacy context.
- Cannot Write DateTime Kind=Local to timestamptzFix: A save that worked before the Npgsql 6 upgrade now fails on a DateTime property
- PostgreSQL warns about a collation version mismatch after an OS upgradeFix: WARNING: database "mydb" has a collation version mismatch