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

**URL:** https://meta.discourse.org/t/backups-fail-with-postgres-16-database-and-all-pg-13/343432
**Category:** Support
**Created:** [December 19, 2024, 5:58pm UTC](https://meta.discourse.org/t/backups-fail-with-postgres-16-database-and-all-pg-13/343432 "2024-12-19T17:58:38Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 19, 2024, 5:58pm UTC](https://meta.discourse.org/t/backups-fail-with-postgres-16-database-and-all-pg-13/343432/1 "2024-12-19T17:58:38Z")

</div>

Backups no longer work for a postgres 16 database due to [this commit](https://github.com/discourse/discourse_docker/commit/a0be7c92cee8087c2107b73610d13c85a6bab914#diff-cfbd0f106ae1a179fe1703cb50774d39c71660059b945cd93c551388a49b20bbR56) that installs `postgresql-client-${PG_MAJOR}` rather than `postgresql-client`

Is this solving a problem? Wasn’t the OS-provided psql client working just fine with all versions of postgres?

I was surprised that this client was using PG16 on a Digital Ocean database, but I thought I knew that some CDCK hosting was using PG15 now.

Is there some better way to get a working backup than something like this:

```plaintext
run:
  - exec:
      cd: /var/www/discourse
      cmd: 
        - apt-get update && apt-get remove -y postgresql-client-13 && apt-get install -y postgresql-client-16

```

Maybe I can set PG\_MAJOR in an ENV variable?

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [December 19, 2024, 6:55pm UTC](https://meta.discourse.org/t/backups-fail-with-postgres-16-database-and-all-pg-13/343432/2 "2024-12-19T18:55:02Z")

</div>

> [@pfaffman](#):
>
> Is this solving a problem?

Yep, that seems to be the case.

From the [PR](https://github.com/discourse/discourse_docker/pull/892):

> I discovered this bug when a Discourse backup was taken using `pg_dump` versioned 17.2 which cannot be restored onto postgres clusters \< 17.2.

Seems like you’re between a rock and a hard place here ([PostgreSQL: Documentation: 18: pg\_dump](https://www.postgresql.org/docs/current/app-pgdump.html))

> Because pg\_dump is used to transfer data to newer versions of PostgreSQL, the output of pg\_dump can be expected to load into PostgreSQL server versions newer than pg\_dump’s version. pg\_dump can also dump from PostgreSQL servers older than its own version. (Currently, servers back to version 9.2 are supported.) However, pg\_dump cannot dump from PostgreSQL servers newer than its own major version; it will refuse to even try, rather than risk making an invalid dump. Also, it is not guaranteed that pg\_dump’s output can be loaded into a server of an older major version — not even if the dump was taken from a server of that version. Loading a dump file into an older server may require manual editing of the dump file to remove syntax not understood by the older server.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 19, 2024, 7:44pm UTC](https://meta.discourse.org/t/backups-fail-with-postgres-16-database-and-all-pg-13/343432/3 "2024-12-19T19:44:56Z")

</div>

> [@RGJ](#):
>
> From the [PR](https://github.com/discourse/discourse_docker/pull/892):

Oops. And I thought I read the PR. Given that I am a native English speaker with a PhD, you’d think I could do better. 🤷

> [@pfaffman](#):
>
> Maybe I can set PG\_MAJOR in an ENV variable?

No. I can’t, since this is what builds the base image.

So, it looks like my fix is about as good as it gets, though if I were more clever I’d expunge the apt stuff that I pull in with the `apt-get update`.

I imagine that some others will have this problem, as it’s often hard to convince various humans and systems that you want PG13 rather than something more recent. And it seem like it was a pretty long time ago that someone who knows said that Discourse was working with PG15.

Thanks, Richard!

---

<div class="post-metadata">

### Author: ![Ed\_S](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ed_s/32/134015_2.png) [@Ed\_S](https://meta.discourse.org/u/Ed_S)
#### Post date: [December 19, 2024, 9:58pm UTC](https://meta.discourse.org/t/backups-fail-with-postgres-16-database-and-all-pg-13/343432/4 "2024-12-19T21:58:07Z")

</div>

Do the backups fail silently??

(I see my ordinary installation is using version 13, so I take it that this situation is a bit special, although perhaps not terribly rare.)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 20, 2024, 12:13am UTC](https://meta.discourse.org/t/backups-fail-with-postgres-16-database-and-all-pg-13/343432/5 "2024-12-20T00:13:40Z")

</div>

> [@Ed\_S](#):
>
> Do the backups fail silently??

They do not. So it’s pretty obvious, and should happen only to people who know enough to manage their own postgres.

---

<div class="post-metadata">

### Author: ![wilson29thid](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wilson29thid/32/173700_2.png) [@wilson29thid](https://meta.discourse.org/u/wilson29thid)
#### Post date: [June 14, 2025, 9:28pm UTC](https://meta.discourse.org/t/backups-fail-with-postgres-16-database-and-all-pg-13/343432/6 "2025-06-14T21:28:56Z")

</div>

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:

```plaintext
[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](https://forums.29th.org/admin/backups/logs).

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?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [June 14, 2025, 11:06pm UTC](https://meta.discourse.org/t/backups-fail-with-postgres-16-database-and-all-pg-13/343432/7 "2025-06-14T23:06:22Z")

</div>

I think somewhere here i provide the stuff to put those commands on your app.yml.

You can look at the postgres templates for examples, maybe.

---

<div class="post-metadata">

### Author: ![wilson29thid](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wilson29thid/32/173700_2.png) [@wilson29thid](https://meta.discourse.org/u/wilson29thid)
#### Post date: [June 14, 2025, 11:33pm UTC](https://meta.discourse.org/t/backups-fail-with-postgres-16-database-and-all-pg-13/343432/8 "2025-06-14T23:33:36Z")

</div>

Thanks, but I’m not sure I follow. I’m under the impression that the YAML you mentioned in the original post above was simply a way to reduce the commands from the handful I posted above to a single one, but that you still had to manually run it each time you upgrade discourse. Have I misinterpreted?
