# Upgrading PostgreSQL 14 to 18 with pg_upgrade --link

By Oleksandr Marynych. Published 2026-10-15. Topic: PostgreSQL.
Checked on Rocky Linux 9.8, PostgreSQL 14.24, PostgreSQL 18.6, PostGIS 3.4.6, PostGIS 3.6.4.
Canonical: https://marynych.com/posts/postgresql-14-to-18-pg-upgrade-link/

> An in-place major upgrade on Rocky Linux 9 with PGDG packages: what to check in your cluster, the flags that matter, and where extensions bite.

PostgreSQL 14 gets its last release on 12 November 2026. `pg_upgrade --link` moves a cluster to 18 in place, without copying the data: the outage is seconds for a few databases and about a minute for a hundred, whatever their size.

> Create the 18 cluster next to the 14 one on the same filesystem with `initdb --no-data-checksums`, install the 18 build of every extension you use, run `pg_upgrade --check` while 14 is still up, and only then stop 14 and run `pg_upgrade --link`. Until the first start of 18 the old cluster can be started again; after that the only way back is a backup.

## What to check in your cluster

Four facts decide whether the steps below apply as they are. With 14 running:

```console
$ sudo -iu postgres
$ psql -Atc "SHOW data_directory"
$ /usr/pgsql-14/bin/pg_controldata \
    /var/lib/pgsql/14/data | grep checksum
$ psql -Atc "SELECT datname FROM pg_database \
    WHERE datallowconn"
$ psql -d yourdb -Atc "SELECT extname, extversion \
    FROM pg_extension"
$ exit
```

- **Data directory.** `/var/lib/pgsql/14/data` is the package layout, and the paths below apply. Anything else means a systemd drop-in with `Environment=PGDATA=…`, and the 18 unit needs the same drop-in pointing at a sibling directory on the same filesystem.
- **Checksums.** `version: 0` means off, and the new cluster is created with `--no-data-checksums` as below. Any other value means on, and `initdb` then needs no flag: 18 enables checksums by default.
- **Databases.** Extensions live inside each database, so the last query runs once per database on the list.
- **Extensions.** Every one except plpgsql needs its 18 package before the check.

Also grep the configs for settings removed since 14: `stats_temp_directory`, `vacuum_defer_cleanup_age`, `promote_trigger_file`, `old_snapshot_threshold`, `force_parallel_mode`, `db_user_namespace`. Any of them stops 18 from starting.

## Packages

[PGDG](https://yum.postgresql.org/) ships 18 in the same repository file as 14. Disable the AppStream module first, or dnf may pick the Rocky build. Add the 18 packages of your extensions to the install line:

```console
$ sudo dnf -qy module disable postgresql
$ sudo dnf -y install postgresql18-server \
    postgresql18-contrib postgis36_18
```

Keep the 14 packages: pg_upgrade starts the old server with its own binaries to dump the schema.

An extension may have no 18 build of the version you run. PostGIS is the common case: 3.4 exists for 14 only, so the cluster moves to 3.6. pg_upgrade accepts that, because the databases reference the library by the name `postgis-3`, the same for every 3.x. The extension itself is updated inside each database after the start, and that step needs an upgrade path from your old version. The 3.6.4 package knows old versions only up to 3.4.5; from 3.4.6 the step fails with `no update path from version "3.4.6" to version "ANY"`. The missing file is a three-line comment identical to its neighbours:

```console
$ cd /usr/pgsql-18/share/extension
$ sudo cp postgis--3.4.5--ANY.sql \
    postgis--3.4.6--ANY.sql
```

## New cluster and check

`sudo -iu postgres` opens a shell in `/var/lib/pgsql`. pg_upgrade writes its helper scripts into the current directory, so stay there rather than in `/tmp`:

```console
$ sudo -iu postgres
$ /usr/pgsql-18/bin/initdb \
    -D /var/lib/pgsql/18/data --no-data-checksums
$ cp /var/lib/pgsql/14/data/*.conf \
    /var/lib/pgsql/18/data/
$ /usr/pgsql-18/bin/pg_upgrade \
    -b /usr/pgsql-14/bin -B /usr/pgsql-18/bin \
    -d /var/lib/pgsql/14/data \
    -D /var/lib/pgsql/18/data --link --check
$ exit
```

pg_upgrade copies no configuration and initdb writes defaults, so copying every `*.conf` from 14 brings over the client access rules, `listen_addresses` and the locale settings; a fresh 18 `postgresql.conf` differs from the 14 one by a single added line. `-b` and `-B` are the binaries of the two servers, `-d` and `-D` their data directories. The check changes nothing and must end with `*Clusters are compatible*`; a `fatal` line names the problem, most often a missing extension library.

## The window

Stop the applications, take a VM snapshot or a copy of the 14 data directory, then:

```console
$ sudo systemctl stop postgresql-14
$ sudo -iu postgres
$ /usr/pgsql-18/bin/pg_upgrade \
    -b /usr/pgsql-14/bin -B /usr/pgsql-18/bin \
    -d /var/lib/pgsql/14/data \
    -D /var/lib/pgsql/18/data --link --jobs $(nproc)
$ exit
$ sudo systemctl disable postgresql-14
$ sudo systemctl enable --now postgresql-18
```

`--jobs` restores several databases in parallel, one per core: `$(nproc)` is the core count of the machine the command runs on. After `Upgrade Complete` the old cluster is still intact: pg_upgrade only renamed `global/pg_control` to `pg_control.old`, and renaming it back lets 14 start. The first start of 18 is the point of no return, because from then on both clusters share the same table files. A 12 GB cluster with 120 databases and PostGIS in each of them spends 53 seconds between the stop and the start.

## After the start

18 is the first version whose pg_upgrade carries the planner statistics over, so the hours-long `ANALYZE` of earlier upgrades is gone. What remains runs with the server up:

```console
$ sudo -iu postgres
$ /usr/pgsql-18/bin/vacuumdb --all \
    --analyze-in-stages --missing-stats-only
$ /usr/pgsql-18/bin/vacuumdb --all --analyze-only
$ /usr/pgsql-18/bin/psql -f update_extensions.sql
$ exit
```

`--missing-stats-only` analyzes only the tables without statistics; a plain `--analyze-in-stages` would overwrite the transferred ones. `--analyze-only` reseeds the counters autovacuum works from. `update_extensions.sql` exists when pg_upgrade reported `Checking for extension updates notice`; it is one `ALTER EXTENSION … UPDATE` per database and brings every extension to the installed version.

Then take a full backup of the new cluster: its WAL history starts over, so 14 base backups and archives cannot continue into 18.

## Cleanup

Once 18 has started, the old data directory is useless, since rollback is from backup only. Remove it after the checks:

```console
$ sudo -iu postgres
$ ./delete_old_cluster.sh
$ exit
$ sudo dnf -y remove 'postgresql14*' postgis34_14
```

`postgis34_14` stands for the 14 packages of your extensions, as `postgis36_18` did in the install line. The table files survive through the hard links the new cluster holds; only the 14 system catalog goes.
