Infinite loop during postgres upgrade

Hi! Each time I launch /launcher rebuild app I get the following message (even if I launch it again) :

UPGRADE OF POSTGRES COMPLETE
Old 9.5 database is stored at /shared/postgres_data_old
To complete the upgrade, rebuild again using:
./launcher rebuild app

What information do you need to help me?

PS: The first time I ran it, the command stoped because I needed more space

Temporarily, I used the templates/postgres.9.5.template.yml template to avoid downtime. The app is running again, but I’d like to finish the update.

When I do a cleanup I get the following message : Old PostgreSQL backup data cluster detected taking up 1.2G detected. Would you like to remove it? (Y/n):

Sounds like a question for @tgxworld, but I am guessing that it failed due to lack of space but somehow didn’t catch that the upgrade had failed.

How much space do you have? And how big is your database?

Can you provide me with the full log generated during the rebuild? Thank you!

수개월째 같은 문제를 겪고 있으며 설치를 업그레이드할 수 없습니다.

업그레이드 과정이 루프를 돌고 끝내 성공하지 못합니다. rebuild app 실행 중 발생하는 문제 중 하나는 다음과 같습니다:
mv: cannot move '/shared/postgres_data' to '/shared/postgres_data_old': Device or resource busy

Docker 내부에서 확인한 postgres 버전은 다음과 같습니다:

/usr/lib/postgresql/10/bin/postgres --version
postgres (PostgreSQL) 10.14 (Debian 10.14-1.pgdg100+1)

다음과 같은 오류가 발생합니다:

FAILED

--------------------

Pups::ExecError: /root/upgrade_postgres failed with return #<Process::Status: pid 47 exit 1>

Location of failure: /pups/lib/pups/exec_command.rb:112:in `spawn'

exec failed with the params "/root/upgrade_postgres"

0c74c9de4d4315b63c0ef9055631f38c0cf4b3dd0be6500fd83ca0a5b13e0d9d

** 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.

/pups/lib/pups/exec_command.rb 스크립트가 spawn을 실행하는 데 문제가 있는 것으로 보입니다.

다만 앱은 시작할 수 있습니다.
./launcher start app

/shared 디렉터리 내의 파일 목록은 다음과 같습니다:

total 48
drwxr-xr-x 12 root      root     4096 Jan 12 13:12 .
drwxr-xr-x 57 root      root     4096 Dec 15 09:09 ..
drwxr-xr-x  3 discourse www-data 4096 Aug 20  2019 backups
drwxr-xr-x  4 root      root     4096 Aug 19  2019 log
drwxr-xr-x  2 postgres  postgres 4096 Aug 19  2019 postgres_backup
drwx------ 20 postgres  postgres 4096 Jan 12 13:14 postgres_data
drwx------ 19 postgres  postgres 4096 Jan 12 13:12 postgres_data_new
drwxrwxr-x  5 postgres  postgres 4096 Jan 12 13:14 postgres_run
drwxr-xr-x  2 redis     redis    4096 Jan 12 13:07 redis_data
drwxr-xr-x  4 root      root     4096 Aug 19  2019 state
drwxr-xr-x  4 discourse www-data 4096 Jan 12 13:14 tmp
drwxr-xr-x  4 discourse www-data 4096 Sep  8  2019 uploads

어떻게 해야 할까요?

공유 디렉터리가 어떤 종류의 네트워크 마운트인가요?

아니요, 하지만 마침내 해결했습니다!

templates/postgres.template.yml에 있는 두 개의 mv 명령은 성공 여부를 확인하지 않습니다. 스크립트는 이동에 오류가 발생했더라도 항상 UPGRADE OF POSTGRES COMPLETE라고 표시합니다.

저는 해당 명령을 제거한 뒤, 도커에 진입하여 수동으로 디렉토리를 이동했고, 이후의 rebuild app은 이전과 동일하게 정상적으로 작동하고 있습니다! 정말 기쁩니다 :smiley:
감사합니다.

최근 PostgreSQL 13에서 15로의 업그레이드 중 이 문제를 겪었습니다.

우리의 배포 환경에서는 /shared/postgres_data 디렉터리가 더 빠른 NVMe 저장 장치에 마운트되어 있어, 해당 디렉터리를 이동하려고 하면 Device or resource busy 오류 메시지와 함께 실패했습니다.

우리는 postgres 템플릿을 다음과 같이 패치하여 이 문제를 해결했습니다:

diff --git a/templates/postgres.template.yml b/templates/postgres.template.yml
index c24bfe6..03813c4 100644
--- a/templates/postgres.template.yml
+++ b/templates/postgres.template.yml
@@ -139,8 +139,10 @@ run:
            exit 1
          fi
 
-         mv /shared/postgres_data /shared/postgres_data_old
-         mv /shared/postgres_data_new /shared/postgres_data
+         mkdir /shared/postgres_data_old
+         mv /shared/postgres_data/* /shared/postgres_data_old
+         mv /shared/postgres_data_new/* /shared/postgres_data
+         rmdir /shared/postgres_data_new

디렉터리 자체를 조작하려는 대신, 디렉터리 내부의 내용물만 이동하도록 변경했습니다.

데이터베이스 업그레이드의 신뢰성을 높이기 위해 이 변경 사항을 통합해 주시기를 고려해 주시기 바랍니다.

이것이 관련이 있을 것 같습니다: FIX: improve postgres upgrade reliability - Pull Request #989 - discourse/discourse_docker - GitHub

PR가 병합되었습니다 :+1: