How to Upgrade PostgreSQL 14 to 18 With pg_upgrade (Step by Step)
PostgreSQL 14 is now end of life. Here is how to upgrade PostgreSQL 14 to 18 with pg_upgrade: what you need, the exact steps, which transfer mode to pick and how to roll back.
Image: TeQBlogs
To upgrade PostgreSQL 14 to version 18, install PostgreSQL 18 beside your old server, create an empty new cluster with initdb, run pg_upgrade --check, then run pg_upgrade for real and start the new server. With link or clone mode the transfer itself is usually quick, but you must back up first and test the steps on a copy.
PostgreSQL 14 reached end of life on 12 November 2026 with its final release, 14.25, so it will get no more security fixes. This guide follows the official pg_upgrade documentation.
Quick summary
- Why now: PostgreSQL 14 is end of life; 14.25 is its last update.
- Best target: PostgreSQL 18 (current minor 18.7), supported until 14 November 2030.
- Tool:
pg_upgrade, which supports upgrades from 9.2 and later. - Time: link, clone or swap mode is fast; the default copy mode takes longer and needs double the disk space.
- Golden rule: full backup first, and always run
--checkbefore the real upgrade.
Why you should upgrade PostgreSQL 14 now
PostgreSQL supports each major version for five years. Version 14 first shipped on 30 September 2021, and its final minor release came out with the big PostgreSQL security update that fixed 52 flaws. Any vulnerability found after that stays unpatched on 14.
Also read: How to Migrate a Custom GPT to a ChatGPT Plugin Before 11 December
| Target version | Current minor | Supported until | Good for |
|---|---|---|---|
| PostgreSQL 18 | 18.7 | 14 November 2030 | Longest support of the released versions |
| PostgreSQL 17 | 17.12 | 8 November 2029 | Teams that want a version with more time in production |
| PostgreSQL 16 | 16.16 | 9 November 2028 | Apps certified only up to 16 |
| PostgreSQL 15 | 15.20 | 11 November 2027 | Short stopgap only |
| PostgreSQL 19 | RC 2 | Planned GA 19 November 2026 | Testing for now, not production |
What you need before you start
- A full, tested backup of the PostgreSQL 14 cluster.
- PostgreSQL 14 updated to 14.25, the final minor release.
- PostgreSQL 18 binaries installed in their own directory (from the PostgreSQL download page or your distribution’s packages).
- The PostgreSQL 18 builds of every extension you use (for example
pgcryptoor PostGIS). - Enough free disk space: about the size of the data directory for copy mode, much less for link, clone or swap mode.
- A maintenance window, because both servers must be stopped during the upgrade.
How to upgrade PostgreSQL 14 to 18: step by step
The commands below use typical Debian and Ubuntu package paths as an example. Replace the bin and data directories with the ones on your server.

- Back up: take a full backup and confirm you can restore it.
- Install PostgreSQL 18: install the server package and the matching extension packages. Do not run
CREATE EXTENSIONin the new cluster; pg_upgrade copies the schema across. - Create the new cluster: run
initdbfor version 18 with settings compatible with the old cluster (such as encoding and locale). Do not start it. - Copy custom files: copy any custom full-text search dictionaries, synonym or stop-word files to the new installation.
- Set up access: pg_upgrade connects many times, so use
peerauthentication inpg_hba.confor a~/.pgpassfile. - Stop both servers: stop PostgreSQL 14 (and make sure the new cluster is not running).
- Run the check: as the postgres user, run
pg_upgrade -b /usr/lib/postgresql/14/bin -B /usr/lib/postgresql/18/bin -d /var/lib/postgresql/14/main -D /var/lib/postgresql/18/main --link --jobs=4 --check
Fix every problem it reports and run it again until it passes. - Run the upgrade: repeat the same command without
--check. - Restore settings: copy back your
pg_hba.confrules and tunepostgresql.conffor the new server. - Start PostgreSQL 18 and connect your application to a test database first.
- Run the generated scripts: if pg_upgrade created SQL scripts, run them with
psql --username=postgres --file=script.sql postgres. - Refresh statistics: run
vacuumdb --all --analyze-in-stages --missing-stats-onlyand thenvacuumdb --all --analyze-only. - Clean up: once you are happy, delete the old cluster with the script pg_upgrade leaves behind.
PostgreSQL 18’s pg_upgrade carries over most optimizer statistics, but not extended statistics made with CREATE STATISTICS, so step 12 still matters. Add --jobs to vacuumdb to speed it up on servers with several CPU cores.
Copy, link, clone or swap: which mode to use
The transfer mode decides how fast the upgrade is and whether you can fall back to PostgreSQL 14 afterwards.

| Mode | Speed | Disk space | Can you go back to 14? |
|---|---|---|---|
--copy (default) | Slowest | Doubles | Yes, old cluster untouched |
--link | Very fast | Little extra | Only until the new server is started |
--clone | Very fast | Little extra | Yes; needs Btrfs or XFS with reflink on Linux, or APFS on macOS |
--swap | Can be fastest with many tables | Little extra | No, once file transfer starts; restore from backup |
Link, clone and swap need the old and new data directories on the same file system. If your backup is solid and downtime matters, link mode is the common choice; if you want an easy way back, use copy or clone.
If pg_upgrade fails or the check reports errors
- Missing extension library: install the PostgreSQL 18 build of that extension and rerun the check.
- Unsupported data types: columns using
regcollation,regconfig,regdictionary,regnamespace,regoper,regoperator,regprocorregprocedureblock the upgrade and must be changed first. - Connection or password errors: switch to peer authentication or a
.pgpassfile for the upgrade. - Need to roll back: if you used copy mode, or link mode without starting the new server, you can restart PostgreSQL 14. After link mode with the new server started, or after swap mode, restore from backup.
- Replicas and logical replication: standbys and logical replication setups have extra steps in the documentation; the simplest route is often to rebuild standbys after the upgrade.
Small databases can also move with pg_dump and pg_restore. If you go that way, use the newly patched client tools and never restore a dump file from an untrusted source. For broader server hygiene, see our guides on updating PHP safely and patching OpenSSH on servers. Businesses without in-house database skills can ask an IT managed services partner to run the upgrade in a planned window.
Frequently asked questions
Can I upgrade PostgreSQL 14 directly to 18?
Yes. pg_upgrade supports upgrades from version 9.2 and later straight to the current major release, so you do not need to stop at 15, 16 or 17.
How long does pg_upgrade take?
It depends on database size and mode. Copy mode copies every data file, while link, clone and swap modes avoid most copying and usually finish much faster.
Does pg_upgrade keep my users, passwords and data?
Yes. It moves all databases, roles and data into the new cluster. You still need to restore your own pg_hba.conf rules and server settings.
Should I wait for PostgreSQL 19?
PostgreSQL 19 is only planned for general availability on 19 November 2026. If you are on 14 today, moving to 18 now removes the end-of-life risk, and 18 is supported until November 2030.
Bottom line
PostgreSQL 14 is out of support, and pg_upgrade makes the jump to 18 a short, well-documented job. Back up, run --check until it is clean, pick the right transfer mode, then refresh statistics and test your app before deleting the old cluster.
Sources
- PostgreSQL documentation: pg_upgrade
- PostgreSQL: Versioning policy
- PostgreSQL: 18.7, 17.12, 16.16, 15.20, 14.25 and 19 RC 2 released
