升级 v3.5.2 -\u003e v3.6.0.beta2 后数据库访问问题

  • v3.5.2 → v3.5.2
  • v3.6.0.beta2 → v3.6.0.beta2

此帖子引导我到了这里:Upgrade failed. Database stopped. (multisite install)

我现在遇到了数据库访问问题:


2025-11-02 17:13:51.212 UTC [1975] postgres@c_discourse LOG:  提供的用户名 (postgres) 和已验证的用户名 (discourse) 不匹配 
2025-11-02 17:13:51.212 UTC [1975] postgres@c_discourse FATAL:  用户“postgres”的对等身份验证失败 
2025-11-02 17:13:51.212 UTC [1975] postgres@c_discourse DETAIL:  连接匹配 pg_hba.conf 第 89 行:“local   all             postgres       
                        peer”
postgres=# \l
数据库列表
名称     |  所有者   | 编码 | 区域设置提供程序 |   排序规则   |    Ctype    | ICU 区域设置 | ICU 规则 |   访问权限
-------------±---------±---------±----------------±------------±------------±-----------±----------±-----------------------
b_discourse | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =Tc/postgres          +
|          |          |                 |             |             |            |           | postgres=CTc/postgres +
|          |          |                 |             |             |            |           | discourse=CTc/postgres
c_discourse | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =Tc/postgres          +
|          |          |                 |             |             |            |           | postgres=CTc/postgres +
|          |          |                 |             |             |            |           | discourse=CTc/postgres
discourse   | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =Tc/postgres          +
|          |          |                 |             |             |            |           | postgres=CTc/postgres +
|          |          |                 |             |             |            |           | discourse=CTc/postgres
postgres    | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           |
template0   | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =c/postgres           +
|          |          |                 |             |             |            |           | postgres=CTc/postgres
template1   | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =c/postgres           +
|          |          |                 |             |             |            |           | postgres=CTc/postgres
(6 行)


multisite.yaml 在这些版本之间发生了变化。

原始:
secondsite:
adapter: postgresql
database: b_discourse
pool: 25
timeout: 5000
db_id: 2
host_names:
- ``forum.domain.com

新:
mlp:
adapter: postgresql
database: discourse_mlp
username: discourse_mlp
password: applejack
host: dbhost
pool: 5
timeout: 5000
host_names:
- discourse.nudderdomain.com
- discourse.nudderdomain.internal

我从未为 multisite 设置过任何密码或用户,因为在设置它们时,原始模板中不需要或未列出它们。

最初,我无法升级,因为 multisite 由于 multisite.yml 中列出的两个站点的权限问题而失败。在 multisite.yml 中添加 postgres 作为用户并未能成功迁移。现在我看到也许我应该尝试 discourse?

仅仅将所有者更改为 discourse 能修复它吗?我需要为 multisite 添加用户和密码以使其与当前匹配吗?

这里最好的长期解决方案是什么?

您的帖子很难阅读,因此我已将其设为不公开。请修复格式,我将重新公开它。

2 个赞

我很遗憾地付出了巨大的努力来使其尽可能易于理解/连贯。

我知道我的意思。:wink:

编辑:好的,明白了。我使用的另一个论坛略有不同。我在代码块前后的一行上使用三个反引号。现在我明白了。这个论坛的第一个反引号集会插入一个窗口供我粘贴。我无法理解为什么三个反引号不起作用,而 < / > 没有给我真正想要的东西。

1 个赞

如果您需要在帖子中进行大量 Markdown 操作,可以切换到 Markdown 编辑器。

您的数据库密码问题很奇怪。您是否考虑过迁移到新服务器?这可能比解决此问题更快、更容易。

您是否遵循了这些说明?(看起来没有?)

很有可能,但请确保您拥有像 multisite 安装主题中的内容。

如果您的站点现在可以正常运行,那么我也鼓励您进行一次全新的 multisite 安装,然后备份/恢复数据库。您可以复制所有其他内容,如 将 Discourse 站点迁移到另一台 VPS (使用 rsync) 中所述。

我想知道为什么我的数据库被命名为 b_discourse 和 c_discourse。现在我知道原因了。 :wink:

## 插件放在这里
## 详情请参见 https://meta.discourse.org/t/19157
hooks:
  after_postgres:
     - exec: sudo -u postgres createdb b_discourse || exit 0
     - exec:
          stdin: |
            grant all privileges on database b_discourse to discourse;
          cmd: sudo -u postgres psql b_discourse
          raise_on_fail: false

     - exec: sudo -u postgres createdb c_discourse || exit 0
     - exec:
          stdin: |
            grant all privileges on database c_discourse to discourse;
          cmd: sudo -u postgres psql c_discourse
          raise_on_fail: false

     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "create extension if not exists pg_trgm;"'

我不太明白权限是如何授予的,所以我想知道这些。(上面两个有问题的数据库的截图):

好消息坏消息。 :frowning:
现在我们想要 :frowning:

2025-11-07 18:05:41.555 UTC [4724] discourse@b_discourse ERROR:  must be owner of extension vector
2025-11-07 18:05:41.555 UTC [4724] discourse@b_discourse STATEMENT:  ALTER EXTENSION vector UPDATE TO '0.8.0';
2025-11-07 18:05:41.752 UTC [4725] discourse@c_discourse ERROR:  must be owner of extension vector
2025-11-07 18:05:41.752 UTC [4725] discourse@c_discourse STATEMENT:  ALTER EXTENSION vector UPDATE TO '0.8.0';

而不是

ALTER EXTENSION vector UPDATE TO ‘0.7.0’;

但是:

b_discourse=# ALTER EXTENSION vector UPDATE TO '0.8.0';
ERROR:  extension "vector" has no update path from version "0.7.4" to version "0.8.0"

我一直对直接更改数据库所有者持谨慎态度,但我想这可能是下一步。

有没有办法让 ./launcherpostgres 用户身份连接?这似乎可以解决我这里所有的升级问题。

b_discourse=# select e.extname, u.usename 
             from pg_extension e 
             join pg_user u on e.extowner = u.usesysid;
 extname  |  usename  
----------+-----------
 plpgsql  | postgres
 hstore   | postgres
 pg_trgm  | postgres
 unaccent | discourse
 vector   | postgres
(5 rows)

似乎只是尝试更改扩展所有者就存在“问题”。我找到的第一个参考是在 2017 年,而在 2022 年仍然没有实现。

我使用 apt 安装了新的扩展并使其正常工作。天哪。现在要做正确的备份并更新到 Postgres 15。但今晚不行。 :wink:

我的历史记录似乎被清除了,所以我无法确切告诉你我是如何做到的,但请注意。它需要 postgres 13 并会尝试重新安装它。

附注:事实证明我开启了自动备份但忘记了它们。并不是说我知道它们在哪里。我将设置一个 rsync 进程将它们放到我进行其他服务器备份的目录中。

2 个赞