バックアップからの復元が失敗:Postgres インデックスの作成に失敗

皆様、こんにちは

Discourse を何年も問題なく運用してきました。

本日、以前使用していた 2.4.0beta 系バージョンから現在の 2.5.0beta5 への Web UI アップグレードを試みました。しかし、これはうまくいきませんでした。詳細なメモは残していませんが、postgres データディレクトリの所有者が正しくないため、PostgreSQL が正常に起動しなかったようです。

そこで、古いコンテナの 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>'
Trying to rollback...
Rolling back...
Cleaning stuff up...

今後の対応についてご助言いただければ幸いです。

ありがとうございます
–dustin

ダスティンさん、ようこそ。お困りのようで申し訳ありません。

インデックスが破損しています。こちらをご覧ください:PostgreSQL 12 update - #238

「いいね!」 1

返信ありがとうございます。結局、新しいアプリを作成してバックアップから復元しようとする代わりに、元のアプリに戻り、./launcher rebuild appを数回実行しました(ルート権限で実行しましたが、必要だとは思いませんでした。ただし、最初にサイトをルートで設定したので、理にかなっています)。これでサイトが復旧しました!やった!

friendly-lookingなアップグレードボタンを不用意に触らないようにと肝に銘じておきましょう!

ありがとう、
–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

ああ、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

はい、破損したインデックスについては私どもも慎重に調査しております。ご迷惑をおかけし申し訳ございません。理論的にはこのようなことはあり得ないはずですが、理論と実践の違いはご存知の通りです。PG12 では、この問題に対してより耐性が高まることを願っております。

「いいね!」 1

それは聞いてよかったですね。これは、何年もの間「設定して忘れ去る」スタイルで楽しんできた私にとって、初めて直面する小さな問題です(どのマシンで動いているかも、よく忘れています)。ありがとう、–ダスティン

「いいね!」 1