Backups fail with Postgres 16 database (and all PG>13)

Hi all, I ran into this issue today. The symptom was we’d been getting alerts for 6 days or so that backups were failing, and the key log lines appeared to be:

[2025-06-14 03:30:20] pg_dump: error: aborting because of server version mismatch
[2025-06-14 03:30:20] pg_dump: detail: server version: 16.9; pg_dump version: 15.12 (Debian 15.12-1.pgdg120+1)

I run Discourse on ubuntu running on a digital ocean droplet, using the recommended install guide. But I use Digital Ocean’s Managed Postgres database rather than a postgres container. Looking at my database, it’s running pg 16. I don’t think they upgraded it recently (and I wouldn’t expect a major version upgrade to be automatic anyway), but I’ve emailed their support to double check.

Anyway, my research led me to this page. I wasn’t sure where to put the YAML that @pfaffman posted, so I ran the commands manually, and thought I’d share for anyone else stumbling upon this:

  • cd /var/discourse
  • launcher enter app
  • apt list --installed | grep postgres # to confirm that the version currently installed is 15
  • apt-get update
  • apt-get remove postgresql-client-15
  • apt-get install postgresql-client-16

I then triggered a manual backup on the admin backups page.

This seems to have temporarily fixed the problem, but as @pfaffman has pointed out, I expect that the next time I upgrade discourse, it will revert back to postgresql-client-15, and backups will stop working again, requiring the above manual intervention.

Is there any solution to this issue apart from having to repeat these steps every time I upgrade discourse?