升级问题:由于重复键导致升级失败,快照恢复失败

我在运行最新升级时似乎遇到了问题,失败原因如下:

PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_users_on_username_lower"
DETAIL:  Key (username_lower)=(scottie) already exists.

我尝试通过访问 Rails 控制台或直接操作 Postgres 数据库来删除该用户以进行恢复,但始终收到服务器未运行的错误。

以下是我在启动应用后尝试运行 rails 的输出:

FAILED

--------------------

Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 3743 exit 1>

Location of failure: /pups/lib/pups/exec_command.rb:112:in `spawn'

exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}

c744729efb7a5813699e2fe8fa46ab551352d45ada8dcb9204121508364f8438

** FAILED TO BOOTSTRAP ** 请向上滚动并查找更早的错误消息,可能不止一条。

./discourse-doctor 可能有助于诊断问题。

root@kForum:/var/discourse# ./launcher start app

starting up existing container

+ /usr/bin/docker start app

app

root@kForum:/var/discourse# ./launcher enter app

root@kForum-app:/var/www/discourse# rails c

bundler: failed to load command: pry (/var/www/discourse/vendor/bundle/ruby/2.7.0/bin/pry)

PG::ConnectionBad: could not connect to server: No such file or directory

Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

以下是我尝试运行 postgres 的输出:

root@kForum:/var/discourse# ./launcher enter app

root@kForum-app:/var/www/discourse# su discourse

discourse@kForum-app:/var/www/discourse$ psql discourse

psql: error: could not connect to server: No such file or directory

Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

discourse@kForum-app:/var/www/discourse$

我正在 DigitalOcean 上恢复之前的快照以回到正常工作状态,但奇怪(甚至令人担忧)的是,即使恢复了快照,网站似乎仍未恢复运行。该快照是在超过 24 小时前创建的,当时我知道论坛运行正常,因此这应该与我尝试的升级无关。

在我恢复的快照中,当我尝试停止/启动/重启应用时,看到的错误如下:

root@kForum:/var/discourse# ./launcher restart app

+ /usr/bin/docker stop -t 10 app

app

starting up existing container

+ /usr/bin/docker start app

Error response from daemon: container "a1023d05a7b4de25ded1aa69ad49caed9fa59d15fa8e8130d32db82934139e6b": already exists

Error: failed to start containers: app

root@kForum:/var/discourse#

最后,我运行了 discourse-doctor,这似乎是失败的相关部分?

Checking cluster versions                                   ok

The source cluster was not shut down cleanly.
Failure, exiting
-------------------------------------------------------------------------------------
UPGRADE OF POSTGRES FAILED

Please visit https://meta.discourse.org/t/postgresql-13-update/172563 for support.

You can run ./launcher start app to restart your app in the meanwhile



FAILED
--------------------
Pups::ExecError: /root/upgrade_postgres failed with return #<Process::Status: pid 46 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:112:in `spawn'
exec failed with the params "/root/upgrade_postgres"
c98d1b076faed9b0c728cd944b3f2436afc9e266910b82a644c71fd80b42f073
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
==================== END REBUILD LOG ====================
Failed to rebuild app.

Checking your domain name . . .

Connection to forum.kirupa.com succeeded.
You should probably remove any non-standard plugins and rebuild.
Attempting to restart existing container. . . 

starting up existing container
+ /usr/bin/docker start app
Error response from daemon: driver failed programming external connectivity on endpoint app (78a35e0f12e5af560bd1f991ead900fefd0c81570cc4582fe99aaa5e56b238e8): Error starting userland proxy: listen tcp 0.0.0.0:443: bind: address already in use
Error: failed to start containers: app
Failed to restart the container.


==================== PLUGINS ====================
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-solved.git
          - git clone https://github.com/discourse/discourse-sitemap.git

No non-official plugins detected.

See https://github.com/discourse/discourse/blob/master/lib/plugin/metadata.rb for the official list.

========================================
Discourse version at forum.kirupa.com: NOT FOUND
Discourse version at localhost: NOT FOUND

对此情况有何看法?恢复论坛是我的首要目标,解决升级失败是次要目标。

谢谢,
Kirupa

你应该看看这里——这似乎是同一个问题:Help! Upgrade led to complete fail

我昨天遇到一个我认为类似的情况(参见 Help! Upgrade led to complete fail - #8 by Judith

  • 将 postgres_data_old 重命名为 postgres_data
  • 重启旧容器
  • 通过重命名重复的用户(或者那些因大小写不同而被视为重复的用户)来修复损坏的索引问题
  • 在 users 表上重建索引,确保所有索引都已修复
  • 按照 PostgreSQL 13 更新 中的说明切换到 PostgreSQL 12 模板
  • 重新构建以完成升级
  • 成功后,你可以将模板改回并继续完成升级
  • 请注意,你不仅需要更新用户名,还需要更新 username_lower

我昨天修复的那个案例中,存在一个可追溯到 2020 年 2 月的重复用户名,因此你可能不想通过恢复旧数据库来解决这个问题。

要解决这个问题,你需要了解如何使用 PostgreSQL 命令行修改记录、重建数据库,并处理 PostgreSQL 13 升级过程中复杂但有详细文档说明的问题。

如果你有 500 美元的预算,可以联系我。我的联系方式在我的个人资料中。

@pfaffman - 刚通过你的联系表单给你发了消息 :slight_smile:

我回复了。如果你没收到,那可能是你填错了地址?

1 个赞

为了就此做个了结,@pfaffman 真是个奇才。他非常迅速地解决了论坛升级(以及一系列相关问题)的难题 :slight_smile:

3 个赞

我也遇到了同样的问题,但不想花 500 美元来解决。我有服务器的 SFTP 访问权限,所以不能直接在记事本中打开数据库并重命名冲突的用户名吗?

或者,如果有人能以大约 50 美元的价格解决这个问题,请联系我。

您可以在 PG::UniqueViolation Problem during 3.1.0.beta4 upgrade - #3 by ahmedeldeep 上查看,有人在那里很好地描述了他们所做的操作。

您需要一个 SSH 客户端,而不是 SFTP。如果您使用的是 Digital Ocean,可以在其网站上使用控制台。