# PostgreSQL 18 备份失败

**URL:** https://meta.discourse.org/t/backup-fails-with-postgres-18/403289
**Category:** Support
**Created:** [2026 年5 月 19 日 06:32 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289 "2026-05-19T06:32:20Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [2026 年5 月 19 日 06:32 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289/1 "2026-05-19T06:32:21Z")

</div>

我们 Discourse 实例的数据库并非本地容器，而是使用了一个集中式数据库集群。最近，中央 PostgreSQL 已更新至 18.3 版本。我注意到现在的 Discourse 备份失败了：

```plaintext
[2026-05-19 03:37:37] [STARTED]
[2026-05-19 03:37:37] 'system' 已启动备份！
[2026-05-19 03:37:37] 将备份标记为运行中...
[2026-05-19 03:37:37] 确保 '/var/www/discourse/tmp/backups/default/2026-05-19-033737' 存在...
[2026-05-19 03:37:37] 确保 '/var/www/discourse/public/backups/default' 存在...
[2026-05-19 03:37:37] 更新元数据...
[2026-05-19 03:37:37] 转储数据库的公共架构...
[2026-05-19 03:37:37] pg_dump: 错误：因服务器版本不匹配而中止
[2026-05-19 03:37:37] pg_dump: 详情：服务器版本：18.3 (Ubuntu 18.3-1.pgdg24.04+1)；pg_dump 版本：15.15 (Debian 15.15-1.pgdg12+1)
[2026-05-19 03:37:37] 异常：pg_dump 失败
[2026-05-19 03:37:37] /var/www/discourse/lib/backup_restore/creator.rb:173:in 'BackupRestore::Creator#dump_public_schema'
/var/www/discourse/lib/backup_restore/creator.rb:36:in 'BackupRestore::Creator#run'
/var/www/discourse/lib/backup_restore.rb:13:in 'BackupRestore.backup!'
/var/www/discourse/app/jobs/regular/create_backup.rb:10:in 'Jobs::CreateBackup#execute'

```

有什么修复建议吗？

---

<div class="post-metadata">

### Author: ![Ethsim2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethsim2/32/522255_2.png) [@Ethsim2](https://meta.discourse.org/u/Ethsim2)
#### Post date: [2026 年5 月 19 日 11:02 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289/2 "2026-05-19T11:02:22Z")

</div>

这看起来像是 PostgreSQL 客户端与服务器的版本不匹配。

备份操作是在 Discourse 容器中执行的，其中 `pg_dump` 的版本为 `15.15`，而外部 PostgreSQL 服务器的版本为 `18.3`：

```plaintext
server version: 18.3; pg_dump version: 15.15

```

除非 Discourse 团队明确建议，否则我对修改 Discourse 容器会持谨慎态度。我的第一反应是保持外部数据库集群与 Discourse 当前预期或支持的 PostgreSQL 版本保持一致。

---

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [2026 年5 月 19 日 11:19 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289/3 "2026-05-19T11:19:56Z")

</div>

好的，明白了。在这种情况下，我们别无选择，因为另一个使用相同数据库集群的项目需要 18 个资源。嗯，听起来我们需要一台独立的数据库服务器，专门分配 15 个资源给 Discourse。

CDCK 方面有什么意见吗？

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [2026 年5 月 19 日 13:00 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289/4 "2026-05-19T13:00:02Z")

</div>

或许可以原地升级客户端？

鉴于您似乎已经证明了与 PG 18 的兼容性，因为您正在将其用作生产数据库，这看起来风险较低。

---

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [2026 年5 月 19 日 13:19 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289/5 "2026-05-19T13:19:04Z")

</div>

我之前用外部 PostgreSQL 18 和一个临时的 Discourse 安装做过一次快速测试，没有发现问题。但说实话，那只是“快速粗糙”的测试，并非“深入”测试。不过，系统已经稳定运行两周了，所以我估计应该没问题。目前唯一的问题是 Discourse 内部的备份功能。另一方面，数据库服务器本身（运行在 LXC 容器中）也已单独进行了备份。

---

<div class="post-metadata">

### Author: ![ted](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ted/32/283882_2.png) [@ted](https://meta.discourse.org/u/ted)
#### Post date: [2026 年5 月 20 日 05:27 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289/7 "2026-05-20T05:27:33Z")

</div>

> [@Thomas\_Rother](#):
>
> CDCK 方面有任何评论吗？

过去的政策是每隔一个版本进行升级。然而，PostgreSQL 17 发布已过去 1.5 年，而官方 Docker 镜像仍在使用 15 版本，因此我不确定这一政策是否仍然适用。

过去有一些几乎相同的话题可供参考，例如：[Any chance to upgrade the postgres-client version?](https://meta.discourse.org/t/any-chance-to-upgrade-the-postgres-client-version/215063)

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [2026 年5 月 20 日 05:39 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289/8 "2026-05-20T05:39:23Z")

</div>

只是想到一个问题——你能直接从命令行在 pg 服务器上转储数据吗？

---

<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: [2026 年5 月 20 日 15:47 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289/9 "2026-05-20T15:47:51Z")

</div>

您可以在 `app.yml` 中添加代码，将 PostgreSQL 更新到匹配的版本。我以前做过，但找不到笔记了。最简单的做法是进入容器，运行 `apt` 命令安装正确的 PostgreSQL 客户端，然后尝试备份。一旦成功，将这些命令添加到 `app.yml` 中的 `exec` 命令里，这样在下次重建时就能自动生效。

如果您需要有人一步步指导，可以给我发邮件，或在 #Marketplace 频道发帖。

---

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [2026 年5 月 21 日 16:31 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289/10 "2026-05-21T16:31:36Z")

</div>

嗯，这相当简单：

1. ./launcher enter web\_only
2. sudo apt-get install postgresql

这将把 postgres 包升级到 V. 18 版本。  
然后从管理界面启动备份，看起来成功了。

```plaintext
[2026-05-21 16:26:50] 'admin' 已启动备份！
[2026-05-21 16:26:50] 将备份标记为运行中...
[2026-05-21 16:26:50] 确保 '/var/www/discourse/tmp/backups/default/2026-05-21-162650' 存在...
[2026-05-21 16:26:50] 确保 '/var/www/discourse/public/backups/default' 存在...
[2026-05-21 16:26:50] 更新元数据...
[2026-05-21 16:26:50] 转储数据库的公共架构...
[2026-05-21 16:26:50] pg_dump: 执行 SELECT pg_catalog.set_config('search_path', '', false);
[2026-05-21 16:26:50] pg_dump: 最后一个内置 OID 是 16383
[2026-05-21 16:26:50] pg_dump: 读取扩展
[2026-05-21 16:26:50] pg_dump: 识别扩展成员
[2026-05-21 16:26:50] pg_dump: 读取架构
[2026-05-21 16:26:50] pg_dump: 读取用户定义的表
[2026-05-21 16:26:50] pg_dump: 读取用户定义的函数
[2026-05-21 16:26:50] pg_dump: 读取用户定义的类型
[2026-05-21 16:26:50] pg_dump: 读取过程语言
[2026-05-21 16:26:50] pg_dump: 读取用户定义的聚合函数
[2026-05-21 16:26:50] pg_dump: 读取用户定义的运算符
[2026-05-21 16:26:50] pg_dump: 读取用户定义的访问方法
[2026-05-21 16:26:50] pg_dump: 读取用户定义的运算符类
[2026-05-21 16:26:50] pg_dump: 读取用户定义的运算符族
[... .... ...]
[2026-05-21 16:26:57] 完成备份...
[2026-05-21 16:26:57] 创建归档：netzwissen-forum-2026-05-21-162650-v20260520064255.tar.gz
[2026-05-21 16:26:57] 确保归档尚未存在...
[2026-05-21 16:26:57] 创建空归档...
[2026-05-21 16:26:57] 归档数据转储...
[2026-05-21 16:26:57] 归档上传文件...
[2026-05-21 16:26:58] 删除临时目录 '/var/www/discourse/tmp/backups/default/2026-05-21-162650'...
[2026-05-21 16:26:58] 对归档进行 gzip 压缩，这可能需要一些时间...

```

---

<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: [2026 年5 月 21 日 16:47 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289/11 "2026-05-21T16:47:41Z")

</div>

不错！我可能会尝试专门安装 pg18 客户端组件，以避免将来自动切换到 19 版本。此外，你还需要将这些命令添加到 app.yml 中，除非你希望在每次升级时手动执行这些操作。

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2026 年6 月 23 日 19:12 UTC](https://meta.discourse.org/t/backup-fails-with-postgres-18/403289/13 "2026-06-23T19:12:52Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
