PostgreSQL 18 upgrade left Discourse using PostgreSQL 15 binaries

I am running Discourse in a standalone Docker container on /var/discourse.

I attempted to upgrade the embedded PostgreSQL database from version 15 to 18. The upgrade appeared to complete, and the active data directory now reports:

/shared/postgres_data/PG_VERSION
18

However, the rebuilt Discourse container still contains only PostgreSQL 15 binaries:

/usr/lib/postgresql/15/bin/postgres
postgres (PostgreSQL) 15.18

The PostgreSQL service is configured to run:

/usr/lib/postgresql/15/bin/postmaster -D /etc/postgresql/15/main

while the actual Discourse data directory is mounted at:

/shared/postgres_data

PostgreSQL consequently fails with:

FATAL: database files are incompatible with server

DETAIL: The data directory was initialized by PostgreSQL version 18,
which is not compatible with this version 15.18
(Debian 15.18-1.pgdg12+1).

I understand that recent Discourse Docker images are supposed to include PostgreSQL 18 binaries. I changed app.yml to use the PostgreSQL 18 template and rebuilt the app, but the resulting container still has PostgreSQL 15 binaries and the service script still points to /etc/postgresql/15/main.

The relevant portion of my current service configuration is:

HOME=/var/lib/postgresql USER=postgres exec thpoff \
chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert \
/usr/lib/postgresql/15/bin/postmaster -D /etc/postgresql/15/main

My questions are:

  1. What is the correct way to rebuild or update the Discourse container so that it actually contains PostgreSQL 18 binaries?

  2. Is there a particular template or image tag that should be used in app.yml?

  3. Once PostgreSQL 18 is available, what is the supported procedure for starting it against the existing /shared/postgres_data directory?

I have not deleted or reinitialised the PostgreSQL 18 data directory. I would prefer to recover the upgraded cluster rather than restore the old PostgreSQL 15 data.

A post was merged into an existing topic: PostgreSQL 18 update for self-hosters