从备份恢复失败:创建 postgres 索引失败

大家好,

几年来我一直顺利运行 Discourse。

今天,我尝试从正在运行的 2.4.0beta 某个版本通过 Web UI 升级到当前版本(2.5.0beta5)。结果……并不顺利。我没有做好详细记录,但看起来 PostgreSQL 未能正确启动,原因是 PostgreSQL 数据目录的所有者不正确。

我打算克隆旧的 containers/app.yml 到 app2,并从备份中恢复。新容器构建成功,我按照命令行恢复备份的说明操作(https://meta.discourse.org/t/restore-a-backup-from-command-line/108034/12)。执行“discourse restore ”时失败,报错如下:

ERROR:  could not create unique index "index_incoming_referers_on_path_and_incoming_domain_id"
DETAIL:  Key (path, incoming_domain_id)=(//viewer/, 16) is duplicated.
EXCEPTION: psql failed: DETAIL:  Key (path, incoming_domain_id)=(//viewer/, 16) is duplicated.
/var/www/discourse/lib/backup_restore/database_restorer.rb:95:in `restore_dump'
/var/www/discourse/lib/backup_restore/database_restorer.rb:26:in `restore'
/var/www/discourse/lib/backup_restore/restorer.rb:49:in `run'
script/discourse:143:in `restore'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-1.0.1/lib/thor/base.rb:485:in `start'
script/discourse:284:in `<top (required)>'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
正在尝试回滚...
正在回滚...
正在清理内容...

非常欢迎任何关于如何继续的建議。

谢谢!
–dustin

欢迎,Dustin。很抱歉您遇到了问题。

您的索引已损坏。请查看 PostgreSQL 12 update - #238

1 个赞

感谢您的回复。最终,我没有尝试创建新应用并从备份恢复,而是回到了原来的应用,并(以 root 身份)多次运行了 ‘./launcher rebuild app’(我原本没想到需要 root 权限,但我想我最初是以 root 身份搭建的站点,所以这很合理),现在我的站点已经恢复了!太好了!

提醒我,永远不要随意点击那个看起来友好的“升级”按钮!

谢谢,
–dustin

2 个赞

您仍然拥有损坏的索引。您仍然希望它不被损坏。

1 个赞

哇,如果升级过程能解决其中一些问题,那就太好了!

所以在安装了数据探索插件,并在 incoming_referers 索引中查看一番,并删除了此处查询列出的其他索引之后:

但我仍然遇到以下提示:

discourse=# REINDEX SCHEMA CONCURRENTLY public;
WARNING:  cannot reindex invalid index "pg_toast.pg_toast_19337_index_ccnew" concurrently, skipping
WARNING:  cannot reindex invalid index "pg_toast.pg_toast_19337_index_ccnew1" concurrently, skipping

而且这些索引也无法被删除!

# drop index pg_toast_19337_index_ccnew1;
ERROR:  index "pg_toast_19337_index_ccnew1" does not exist
1 个赞

[quote=“Dustin_Lang, 帖子:5, 主题:153014”]
警告:无法重新索引无效索引 "pg_toast[/quote]

哦,需要 pg_toast 前缀:

discourse=# drop index pg_toast.pg_toast_19337_index_ccnew1;
DROP INDEX
discourse=# drop index pg_toast.pg_toast_19337_index_ccnew;
DROP INDEX
discourse=# REINDEX SCHEMA CONCURRENTLY public;
REINDEX

是的,我们正在密切关注索引损坏的问题,对此给您带来的不便深表歉意。理论上这不应该发生……但正如人们所说,理论与实践总有差距。我希望 PostgreSQL 12 对……无论是什么问题……具有更强的抵抗力。

1 个赞

听到这个消息很好。这基本上是我在多年“设置后就不管”的愉快使用体验中遇到的第一个小波折(比如,我常常会忘记它到底运行在哪台机器上)。谢谢,–dustin

1 个赞