Subject: Upgrading PostgreSQL 17 to 18 with pg_upgrade: "This utility can only upgrade to PostgreSQL version 18."

From: "revsuine" <[email-masked]>
Date: Fri, 13 Mar 2026 14:14:04 +0000

Hi, I'm trying to upgrade PostgreSQL from 17 to 18. The steps I did
were:

apk add postgresql18
service postgresql stop
pg_versions set-default 18
mv /var/lib/postgresql/17/data /var/lib/postgresql/17/olddata
mkdir -p /var/lib/postgresql/18/{data,tmp}
chown -R postgres:postgres /var/lib/postgresql/18
su postgres
cd /var/lib/postgresql/18/tmp
initdb -D /var/lib/postgresql/18/data --locale=en_GB.UTF-8 --encoding=UTF8 --data-checksums
pg_upgrade -b /usr/libexec/postgresql17 -B /usr/libexec/postgresql18 -d /var/lib/postgresql/17/olddata -D /var/lib/postgresql/18/data

The output is

Performing Consistency Checks
-----------------------------
Checking cluster versions
This utility can only upgrade to PostgreSQL version 18.
Failure, exiting

Any idea what I'm doing wrong?

Thanks in advance.

---

From: Jakub Jirutka <[email-masked]>
Date: Tue, 17 Mar 2026 16:09:44 +0100

Hi,

I just tried to replicate your steps and it works on my system.

Can you verify that /usr/libexec/postgresql is a symlink to
/usr/libexec/postgresql18 after running `pg_versions set-default 18` and that
/usr/bin/initdb is a symlink to /usr/libexec/postgresql/initdb?

Can you verify that /var/lib/postgresql/18/data/PG_VERSION contains `18`?

Jakub