Skip to content
audiotale.net
Sign in
GuidesGuide

How to upgrade PostgreSQL 14 with pg_upgrade: check, link or clone, statistics and rollback

PostgreSQL 14 reached end of life with 14.25. A step-by-step guide to a major upgrade with pg_upgrade, based on the official documentation.

audiotale.net team

· 7 min read

Written by AI from the sources linked below. How we use AI

On this page
  1. In short
  2. Why you have to do this now
  3. Two kinds of upgrade: minor and major
  4. Before you start
  5. Step by step
  6. Copy, link, clone or swap
  7. Reverting if it goes wrong
  8. Standbys
  9. After the upgrade: check the other November advice
  10. Where upgrades trip up
  11. Sources

In short

PostgreSQL 14 stopped receiving security and bug fixes on 12 November 2026, when 14.25 shipped as its final release. To move to a supported version (15 to 19), you do a major-version upgrade. The fastest in-place route is pg_upgrade: install the new binaries, create a new empty cluster with initdb, run pg_upgrade --check, then the real upgrade, then rebuild statistics. This guide walks through that path using the official PostgreSQL 19 documentation, explains the three file modes (copy, link and clone, plus the new swap mode), and says how to back out safely.

Why you have to do this now

The PostgreSQL project's versioning policy lists version 14 as no longer supported, with a final release date of 12 November 2026. The same day the project's announcement for 18.7, 17.12, 16.16, 15.20 and 14.25 said that "PostgreSQL 14 is now end-of-life and will no longer receive security and bug fixes", and that the update fixed 52 security vulnerabilities. Our news article on that release, PostgreSQL 18.7, 17.12, 16.16, 15.20 and 14.25: 52 CVEs fixed, covers the CVE list. The practical point: any vulnerability found in version 14 from now on will not get an upstream fix.

The versioning page also shows how long you get from each target. Version 15 is supported until 11 November 2027, 16 until 9 November 2028, 17 until 8 November 2029, 18 until 14 November 2030 and 19, released on 19 November 2026, until 19 November 2031. If you are going to do the work, aim for the newest version your extensions and drivers support: the later you pick, the longer before your next forced upgrade.

Two kinds of upgrade: minor and major

In 14.25, the major version is 14 and the minor is 25. A minor upgrade (14.24 to 14.25) swaps binaries and needs no data conversion; the pg_upgrade documentation says it "is not required for minor version upgrades". A major upgrade (14 to 18, say) changes internal catalog layout, so the data needs converting.

The documentation names three ways to do a major upgrade:

  1. Dump and restore with pg_dump and pg_restore (or pg_dumpall): the approach pg_upgrade exists to avoid: its documentation calls the dump and restore "typically required" for major upgrades.
  2. pg_upgrade: reuses the existing data files and creates new system tables, which is why it is fast. It is the subject of this guide.
  3. Logical replication to a new server running the newer version, then switching clients across. The documentation's logical replication chapter describes upgrading clusters that already use logical replication, and says migrating them requires every member to be on version 17.0 or later.

Managed services (Amazon RDS and others) have their own upgrade procedures; follow your provider's documentation rather than the self-managed steps below.

Before you start

  • Take a backup you have tested restoring. Link and swap mode can leave the old cluster unusable, as covered below.
  • Check your extensions. pg_upgrade cannot check that external modules are binary compatible, per its documentation. Every shared object file (for example pgcrypto.so) must be installed for the new version. The docs warn not to run CREATE EXTENSION in the new cluster, because the definitions come across from the old one. If extension updates exist, pg_upgrade reports it and writes a script to run later.
  • Check for unsupported column types. The documentation says pg_upgrade does not support databases with table columns of these reg* types: regcollation, regconfig, regdictionary, regnamespace, regoper, regoperator, regproc and regprocedure. (regclass, regdatabase, regrole and regtype can be upgraded.)
  • Trust your superusers. The documentation warns that upgrading "causes the destination to execute arbitrary code of the source superusers' choice", so only upgrade clusters whose superusers you trust.
  • Copy custom text-search files. Dictionary, synonym, thesaurus and stop-word files need copying by hand.
  • Plan for downtime. Nobody may access the clusters during the upgrade.

Step by step

These steps follow the "Usage" section of the PostgreSQL 19 pg_upgrade page, in the order it gives them.

1. Install the new binaries. If your installation directory is not version-specific (for example /usr/local/pgsql), move the old install aside once the old server is shut down. The documentation notes that the graphical installers all use version-specific directories such as /opt/PostgreSQL/19, so no moving is needed there.

2. Initialise the new cluster with initdb, using flags compatible with the old cluster (encoding, locale and so on). The documentation says there is no need to start it. Then install the extension shared object files, as above.

3. Adjust authentication. pg_upgrade connects to both servers several times. The docs suggest peer authentication in pg_hba.conf or a ~/.pgpass file.

4. Run the check first. Always run the pg_upgrade binary from the new server. --check runs the compatibility checks "even if the old server is still running", and outlines manual adjustments to make after the upgrade. If you plan to use --link, --clone, --copy-file-range or --swap, add that option to --check so the mode-specific checks run. Note that when checking a running old server, the old and new port numbers must differ.

pg_upgrade --check \
  --old-bindir /usr/lib/postgresql/14/bin --new-bindir /usr/lib/postgresql/19/bin \
  --old-datadir /var/lib/postgresql/14/main --new-datadir /var/lib/postgresql/19/main \
  --old-port 5432 --new-port 5433 --jobs 4

(The paths are an example of a Debian-style layout; yours will differ.)

5. Stop both servers. Streaming replication and log-shipping standbys must be running during this shutdown so they receive all changes, says the documentation.

6. Run the upgrade with the same options minus --check. pg_upgrade verifies the two clusters are compatible and converts. Setting --jobs to 2 or higher lets it process multiple databases and tablespaces in parallel; the docs suggest the number of CPU cores as a starting point.

7. Start the new server and finish up. If any post-upgrade processing is needed, pg_upgrade prints warnings and generates scripts, which you run with psql --username=postgres --file=script.sql postgres. The documentation cautions that it is generally unsafe to read tables referenced in rebuild scripts until the scripts finish.

8. Rebuild statistics. Unless --no-statistics was given, pg_upgrade carries over most optimiser statistics but not all of them. The docs tell you to run vacuumdb --all --analyze-in-stages --missing-stats-only first, then vacuumdb --all --analyze-only, with --jobs to speed both up.

9. Delete the old cluster only when you are satisfied, using the script pg_upgrade generates.

The file mode decides how quickly the upgrade runs and whether you can go back.

Mode What it does Old cluster afterwards
--copy (default) copies files to the new cluster untouched, restartable
--link hard-links files unsafe to use once the new cluster has started
--clone copy-on-write "reflinks"; needs Linux 4.5+ with Btrfs or XFS (with reflink support), or macOS with APFS untouched, restartable
--copy-file-range uses the copy_file_range system call; Linux and FreeBSD untouched
--swap moves data directories and replaces catalog files; can be fastest with many relations destructively modified once file transfer begins

Link, clone and swap all need the old and new data directories on the same file system. The documentation recommends --sync-method=fsync with --swap, because swap leaves many garbage files in the old cluster that can slow syncfs.

Reverting if it goes wrong

The documentation's "Reverting to old cluster" section reduces to this. If you used --check, or did not use --link or --swap, the old cluster is unmodified and can be restarted. With --link, if the upgrade aborted before linking started the old cluster is unmodified. If linking started but you did not start the new cluster, the only change is a .old suffix on global/pg_control that you remove to reuse the old cluster. If you started the new cluster in link mode, it has written to shared files and "it is unsafe to use the old cluster": restore from backup. If pg_upgrade has reported that the old cluster is no longer safe to start in swap mode, restore from backup too.

Standbys

If you used link mode and have streaming or log-shipping standbys, the docs describe upgrading them quickly with rsync --archive --delete --hard-links --size-only --no-inc-recursive, run from the primary, using the link structure pg_upgrade created. The simpler alternative the docs give is to skip this and recreate the standbys once the new primary is running. Replication slots need attention too: before version 17.0, no slots are copied to the new standby; from 17.0, only logical slots on the primary are.

After the upgrade: check the other November advice

If you move to 18.7 or later, or to 19, you also get the November fixes, with some follow-up from the 18.7 release notes: reindex GIN indexes you suspect are corrupted, pg_trgm GiST indexes using gist_trgm_ops, and B-tree indexes on bpchar columns declared without a length, and take a new full backup if you use incremental backups. REINDEX rebuilds an index from the table data; adding CONCURRENTLY avoids blocking writes, according to its documentation.

Where upgrades trip up

  • Extension files: pg_upgrade cannot check that external modules are binary compatible, so verify them yourself.
  • initdb settings: the documentation says to use flags compatible with the old cluster, and pg_upgrade checks pg_controldata for compatible settings before starting.
  • Statistics: not all statistics are transferred, which is why the docs have you run vacuumdb afterwards.
  • Link or swap mode without a tested backup: the docs list cases where the old cluster cannot be restarted.

Sources

Written by

audiotale.net team

The official account of the people who run audiotale.net: announcements, conversation starters and the newsroom's drafts. Posts written with AI say so. Every other account here is a real person.