백업에서 복원 실패: postgres 인덱스 생성 실패

안녕하세요,

저는 수년 동안 Discourse를 문제없이 운영해 왔습니다.

오늘, 제가 사용하던 2.4.0beta-something 버전에서 현재 버전(2.5.0beta5)으로 웹 UI를 통해 업그레이드를 시도해 보았습니다. 하지만… 잘되지 않았습니다. 자세한 기록을 남기지 않아 정확히는 모르겠지만, postgres 데이터 디렉토리가 올바른 사용자에게 소유되어 있지 않아서 postgres가 제대로 시작되지 않는 것 같았습니다.

기존 컨테이너/app.yml을 app2로 복제하고 백업에서 복원해 보려고 했습니다. 새 컨테이너는 빌드되었고, 커맨드라인으로 백업을 실행하는 방법(Restore a backup from the command line - #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

Dustin, 환영합니다. 문제가 있어서 죄송합니다.

인덱스가 손상되었습니다. PostgreSQL 12 update 을 확인해 보세요.

답장 주셔서 감사합니다. 결국 새 앱을 만들고 백업에서 복원하려는 대신, 원래 앱으로 돌아가서 ‘./launcher rebuild app’ 명령을 루트 권한으로 몇 번 실행해 봤습니다(루트 권한이 필요할 거라고는 생각하지 못했지만, 처음에 사이트를 루트로 설정했기 때문에 그럴 만도 합니다). 이제 사이트가 돌아왔습니다! 환상적이네요!

친근해 보이는 ‘업그레이드’ 버튼을 함부로 건드리지 말라고 스스로에게 일깨워 줘야겠습니다.

감사합니다.
–dustin

여전히 손상된 인덱스를 가지고 있습니다. 여전히 그것이 손상되지 않기를 원합니다.

와, 업그레이드 프로세스에서 이 문제들을 좀 해결해 주면 정말 좋겠네요!

데이터 탐색기 플러그인을 설치하고 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

아, 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 能对这种问题(无论它究竟是什么)具备更强的抵抗力。

그렇게 들으면 다행이네요. 수년간 설정해 두고 방치하는 방식으로 사용해 오면서(어떤 기기에 설치되어 있는지조차 자주 잊을 정도입니다) 처음 겪는 작은 문제라고 할 수 있겠네요.
감사합니다.
–dustin