업그레이드 문제: 중복 키로 인한 업그레이드 실패, 스냅샷 복원 실패

최신 업그레이드를 실행하는 동안 다음 오류로 인해 실패하는 문제가 발생했습니다:

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 ** please scroll up and look for earlier error messages, there may be more than one.

./discourse-doctor may help diagnose the problem.

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

여기서 무슨 일이 일어나고 있는지 의견이 있을까요? 포럼을 정상적으로 되돌리는 것이 제 1순위 목표입니다. 업그레이드 실패를 수정하는 것은 2순위 목표입니다.

감사합니다,
Kirupa

여기를 확인해 보세요 - 같은 문제인 것 같습니다: Help! Upgrade led to complete fail

어제 비슷한 사례를 겪었습니다(Help! Upgrade led to complete fail - #8 by Judith 참조). 대략적으로 말하면, 다음과 같은 조치를 취해야 할 것 같습니다.

  • postgres_data_old를 다시 postgres_data로 이름 변경
  • 이전 컨테이너 재시작
  • 중복된 사용자 이름(또는 대소문자가 달라서 중복으로 간주되는 사용자)을 이름 변경하여 손상된 인덱스 문제 해결
  • 모든 인덱스가 정상적으로 복구되었는지 확인하기 위해 사용자 테이블에 인덱스 생성
  • PostgreSQL 13 업데이트에 설명된 대로 PostgreSQL 12 템플릿으로 변경
  • 업그레이드를 위해 재빌드
  • 정상적으로 작동하면 템플릿을 원래대로 되돌리고 업그레이드를 완료
  • 사용자 이름(username)뿐만 아니라 username_lower도 업데이트해야 한다는 점에 유의

어제 해결한 사례에는 2020년 2월로 거슬러 올라가는 중복 사용자 이름이 있었기 때문에, 이전 데이터베이스를 복원하여 이 문제를 해결하려고 하지 않는 것이 좋습니다.

이를 해결하려면 PostgreSQL 명령줄을 사용하여 레코드를 수정하는 방법, 데이터베이스를 재빌드하는 방법, 그리고 PostgreSQL 13 업그레이드 과정에서 발생하는 복잡하지만 잘 문서화된 문제들을 다루는 방법을 이해해야 합니다.

예산이 500달러 정도 있다면 저에게 연락하실 수 있습니다. 연락처는 프로필에 기재되어 있습니다.

@pfaffman - 방금 연락처 양식을 통해 연락 드렸습니다 :slight_smile:

저는 답장을 보냈습니다. 만약 메일을 받지 못하셨다면, 혹시 잘못된 주소를 입력하신 건 아닌가요?

이 문제를 마무리하기 위해, @pfaffman은 진정한 마법사입니다. 그는 포럼 업그레이드 문제(그리고 관련된 여러 문제들)를 매우 빠르게 해결했습니다 :slight_smile:

저도 같은 문제를 겪고 있지만, 해결하려고 $500를 지불할 생각은 없습니다. 서버에 SFTP 접근 권한이 있으니, 단순히 메모장으로 데이터베이스를 열어 충돌하는 사용자 이름을 변경하는 것은 불가능한가요?

혹시 $50 정도에 해결해 주실 수 있는 분이 계시다면, 제게 연락해 주세요.

PG::UniqueViolation Problem during 3.1.0.beta4 upgrade - #3 by ahmedeldeep 에서 누군가가 자신이 한 일을 꽤 잘 설명하고 있습니다.

SFTP가 아니라 SSH 클라이언트가 필요합니다. Digital Ocean을 사용 중이라면 웹사이트에서 제공하는 콘솔을 사용할 수 있습니다.