긴급, 업그레이드된 빌드 실패 UniqueViolation

discourse를 업그레이드하려고 했는데 다음과 같은 메시지가 표시되었습니다 -

I, [2021-01-21T18:39:25.045454 #1]  INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
2021-01-21 18:39:32.724 UTC [4051] discourse@discourse LOG:  duration: 336.116 ms  statement: UPDATE users
	SET locale = 'en_GB'
	WHERE locale = 'en'
	
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse ERROR:  duplicate key value violates unique constraint "index_users_on_username_lower"
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse DETAIL:  Key (username_lower)=(xyz123) already exists.
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse STATEMENT:  UPDATE users
	SET locale = 'en'
	WHERE locale = 'en_US'
	
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

./launcher enter app와 su postgres -c 'psql discourse'를 시도해 보았지만, 다음과 같은 오류가 발생했습니다 -

psql: error: could not connect to server: 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”?

@merefield 님, 혹시 알고 계신 게 있으신가요? 감사합니다!

안녕하세요.

업그레이드가 실패하면 컨테이너가 중지된 상태로 남습니다. (브라우저를 통해 사이트에 접속해 보시면 그렇게 되어 있는 것을 확인하실 수 있습니다)

따라서 최신으로 정상 작동하는 컨테이너(업그레이드 전 버전)를 시작하지 않은 것일 수 있습니다.

./launcher start app 명령을 실행하여 컨테이너를 시작하고, 컨테이너에 진입한 후 DB CLI로 접속을 시도해 보세요.

감사합니다. 컨테이너를 재시작해 봤는데, 혹시 다른 방법이 있을까요? ./launcher enter app도 시도해 봤는데, 더 해볼 수 있는 게 있을까요?

ubuntu@:/var/discourse$ ./launcher start app
WARNING: Docker version 17.05.0-ce deprecated …
Nothing to do, your container has already started!

컨테이너에 진입할 때 오류가 발생했나요?

에러는 없었지만 ./launcher logs app을 실행한 결과 다음과 같은 출력이 나타났습니다 -

ok: run: redis: (pid 47) 918s
timeout: down: postgres: 1s, normally up, want up
ok: run: redis: (pid 47) 925s
timeout: down: postgres: 0s, normally up, want up
ok: run: redis: (pid 47) 933s
ok: run: postgres: (pid 1855) 0s
supervisor pid: 1847 unicorn pid: 1857
config/unicorn_launcher: line 71: kill: (1857) - No such process
config/unicorn_launcher: line 15: kill: (1857) - No such process
(1847) exiting
ok: run: redis: (pid 47) 938s
timeout: down: postgres: 0s, normally up, want up
ok: run: redis: (pid 47) 945s

ps -ef | grep postgres 명령의 결과는 무엇입니까?

root 38 35 0 19:09 ? 00:00:00 runsv postgres
root 46 38 0 19:09 ? 00:00:00 svlogd /var/log/postgres
root 2573 2571 0 19:31 ? 00:00:00 sv start postgres
root 2575 2497 0 19:31 ? 00:00:00 grep postgres

컨테이너 안에서 실행해야 하나요, 아니면 그냥 리눅스 서버에서 실행해야 하나요?

안쪽에 있습니다. 실행되지 않는 것 같습니다.

postgres 사용자로 수동으로 재시작해야 할 것 같습니다.

재시작하는 빠른 명령을 아시나요?

다음과 같이 시도해 볼 수 있습니다:

su - postgres /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main - 여기서 13을 현재 사용 중인 버전으로 교체하세요.

정상적으로 설치된 시스템에서 프로세스에 표시되는 명령어입니다.

직접 테스트해 보지 않아 보증은 하지 않습니다!

아니요, 이 작업을 수행하지 마세요. 아래 내용을 확인해 주세요.

감사합니다. 제 버전은 12인데, 다음과 같은 오류가 발생했습니다 -

su: invalid option – ‘D’
Try ‘su --help’ for more information.

-D은 유효한 옵션입니다.

코드 스니펫 외부에 하이픈을 포함하지 않았는지 확인해 보세요?

참고로, 버전 13 업그레이드 과정이 실패했을 수 있다고 생각됩니다.

만약 그렇다면 다음 주제를 확인해 보시고, 필요 시 해당 주제에 게시해 주시면 좋겠습니다: PostgreSQL 13 update

네, 저는 아직 12버전을 사용 중입니다…

죄송합니다. 더 상위 수준의 프로세스에 의해 래핑되고 관리되는 것 같습니다.

제 프로세스를 종료하면 자동으로 재시작됩니다.

다음 명령을 시도해 보세요: sv start postgres

루트 권한으로 실행하세요.

Docker 컨테이너 안에서 실행하라는 말씀이신가요? 감사합니다.

네, 서비스가 실행 중인 곳이 바로 그곳입니다.

더 좋은 방법은 이렇게 하는 것입니다: sv restart postgres

그 후 확인하세요:

tail /var/log/postgres/current

정상적인 상태라면 다음과 같은 메시지가 어딘가에 표시됩니다:

2021-01-21 20:21:10.284 UTC [575368] LOG: database system is ready to accept connections

오류 로그를 확인해 주세요 -

root@ip–app:/var/www/discourse# cat /var/log/postgresql/postgresql-12-main.log
2021-01-21 18:12:04.965 UTC [623] FATAL: database files are incompatible with server
2021-01-21 18:12:04.965 UTC [623] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 12.3 (Debian 12.3-1.pgdg100+1).
pg_ctl: could not start server
Examine the log output.