PostgreSQL 10에서 13으로 업데이트 실패

PostgreSQL 13 업데이트에 대한 논의를 계속합니다:

저는 데이터 컨테이너에 postgres.10과 redis 템플릿만 있는 2개 컨테이너 구성의 멀티사이트 환경에서 작업하고 있습니다. 현재 postgres 버전은 10이며 13으로 업그레이드하고 싶습니다. data 컨테이너를 재빌드할 때 발생하는 오류는 다음과 같습니다:

fixing permissions on existing directory /shared/postgres_data_new ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok


Success. You can now start the database server using:

    /usr/lib/postgresql/13/bin/pg_ctl -D /shared/postgres_data_new -l logfile start

Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Hit:2 http://deb.debian.org/debian buster InRelease
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:4 http://apt.postgresql.org/pub/repos/apt buster-pgdg InRelease [104 kB]
Get:5 http://security.debian.org/debian-security buster/updates/main amd64 Packages [291 kB]
Get:6 http://apt.postgresql.org/pub/repos/apt buster-pgdg/main amd64 Packages [231 kB]
Hit:7 https://deb.nodesource.com/node_15.x buster InRelease
Fetched 743 kB in 1s (944 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  postgresql-client-10
Suggested packages:
  postgresql-doc-10
The following NEW packages will be installed:
  postgresql-10 postgresql-client-10
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 6,441 kB of archives.
After this operation, 30.6 MB of additional disk space will be used.
Get:1 http://apt.postgresql.org/pub/repos/apt buster-pgdg/main amd64 postgresql-client-10 amd64 10.17-1.pgdg100+1 [1,439 kB]
Get:2 http://apt.postgresql.org/pub/repos/apt buster-pgdg/main amd64 postgresql-10 amd64 10.17-1.pgdg100+1 [5,002 kB]
Fetched 6,441 kB in 0s (34.9 MB/s)
Selecting previously unselected package postgresql-client-10.
(Reading database ... 43021 files and directories currently installed.)
Preparing to unpack .../postgresql-client-10_10.17-1.pgdg100+1_amd64.deb ...
Unpacking postgresql-client-10 (10.17-1.pgdg100+1) ...
Selecting previously unselected package postgresql-10.
Preparing to unpack .../postgresql-10_10.17-1.pgdg100+1_amd64.deb ...
Unpacking postgresql-10 (10.17-1.pgdg100+1) ...
Setting up postgresql-client-10 (10.17-1.pgdg100+1) ...
update-alternatives: warning: forcing reinstallation of alternative /usr/share/postgresql/13/man/man1/psql.1.gz because link group psql.1.gz is broken
Setting up postgresql-10 (10.17-1.pgdg100+1) ...
Creating new PostgreSQL cluster 10/main ...
/usr/lib/postgresql/10/bin/initdb -D /var/lib/postgresql/10/main --auth-local peer --auth-host md5
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/10/main ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Etc/UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctlcluster 10 main start

Ver Cluster Port Status Owner    Data directory              Log file
10  main    5433 down   postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
update-alternatives: warning: forcing reinstallation of alternative /usr/share/postgresql/13/man/man1/postmaster.1.gz because link group postmaster.1.gz is broken
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Processing triggers for postgresql-common (226.pgdg100+1) ...
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Stopping PostgreSQL 10 database server: main.
Stopping PostgreSQL 13 database server: main.
Performing Consistency Checks
-----------------------------
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 49 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:112:in `spawn'
exec failed with the params "/root/upgrade_postgres"
1f253827e5700e1861c4e586213aaffa8994e452e43b9336301dcd02072e00f4
** 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.

postgres.10 템플릿으로 다시 설정하면 모든 것이 정상적으로 작동합니다.
Postgres 13으로 업그레이드하기 위해 제가 할 수 있는 일이 무엇인지 아시나요?

참고: postgres 12로의 업그레이드도 실패합니다.

데이터 컨테이너를 다음 단계 전에 정지해야 한다는 것을 확인했습니다:

두 컨테이너를 정지한 후 tail -f shared/data/log/var-log/postgres/current 명령을 실행하면 다음과 같은 출력이 표시됩니다:

2021-06-06 16:38:37.411 UTC [113] HINT:  The server must be started by the user that owns the data directory.
2021-06-06 16:38:38.424 GMT [114] LOG:  skipping missing configuration file "/shared/postgres_data/postgresql.auto.conf"
2021-06-06 16:38:38.424 UTC [114] FATAL:  data directory "/shared/postgres_data" has wrong ownership
2021-06-06 16:38:38.424 UTC [114] HINT:  The server must be started by the user that owns the data directory.
2021-06-06 16:38:39.439 GMT [115] LOG:  skipping missing configuration file "/shared/postgres_data/postgresql.auto.conf"
2021-06-06 16:38:39.439 UTC [115] FATAL:  data directory "/shared/postgres_data" has wrong ownership
2021-06-06 16:38:39.439 UTC [115] HINT:  The server must be started by the user that owns the data directory.
2021-06-06 16:38:40.461 GMT [116] LOG:  skipping missing configuration file "/shared/postgres_data/postgresql.auto.conf"
2021-06-06 16:38:40.461 UTC [116] FATAL:  data directory "/shared/postgres_data" has wrong ownership
2021-06-06 16:38:40.461 UTC [116] HINT:  The server must be started by the user that owns the data directory.

이것이 문제의 원인이 될 가능성이 높습니다. 어떻게 수정해야 하나요?

궁금한 게 있어서问一下, postgres_data 디렉터리의 소유주는 누구인가요?

여기 있습니다

root@forum:/var/discourse/shared/data# ls -al
total 32
drwxr-xr-x  8 root root   4096 Jun  6 16:56 .
drwxr-xr-x  4 root root   4096 Mar  3  2019 ..
drwxr-xr-x  3 root root   4096 Jul  8  2018 log
drwxr-xr-x  2 _apt netdev 4096 Jul  7  2018 postgres_backup
drwx------ 20 _apt netdev 4096 Jun  6 17:29 postgres_data
drwx------ 19 _apt netdev 4096 Jun  6 16:56 postgres_data_new
drwxrwsr-x  5 _apt netdev 4096 Jun  6 17:29 postgres_run
drwxr-xr-x  2 lxd  lxd    4096 Jun  6 17:34 redis_data

괜찮나요?

제 설정(컨테이너 2개, postgres 13)에서는 postgres_* 그룹이 netdev가 아니라 render이고, postgres_run 그룹의 권한은 setgid가 아니라 x입니다. 하지만 이것이 어떤 영향을 미치는지는 정확히 모르겠습니다. :sweat_smile:

참고로 redis_data는 uuidd syslog … 입니다.

감사합니다. 저도 잘 모르겠어요 :slight_smile:
누군가 도와주셨으면 좋겠네요!

ls -lan 명령으로 동일한 명령을 실행해 주시겠어요? 이는 소유권 확인에 도움이 됩니다(-n은 사용자 이름을 UID로, 그룹 이름을 GID로 변환합니다). 컨테이너 2개 설정을 사용한 제 사이트의 예시는 다음과 같습니다:

[root@/var/discourse/shared/data]$ ls -lan
total 28
drwxr-xr-x.  7   0   0 4096 Jun  7 22:15 .
drwxr-xr-x.  5   0   0 4096 Jun  7 22:28 ..
drwxr-xr-x.  3   0   0 4096 Jun  7 22:15 log
drwxr-xr-x.  2 105 109 4096 Jun  7 22:15 postgres_backup
drwx------. 19 105 109 4096 Jun  7 22:27 postgres_data
drwxrwxr-x.  3 105 109 4096 Jun  7 22:27 postgres_run
drwxr-xr-x.  2 106 110 4096 Jun  8 00:17 redis_data

물론입니다! 여기 있습니다:

root@forum:/var/discourse/shared/data# ls -lan
total 32
drwxr-xr-x  8   0   0 4096 Jun  6 16:56 .
drwxr-xr-x  4   0   0 4096 Mar  3  2019 ..
drwxr-xr-x  3   0   0 4096 Jul  8  2018 log
drwxr-xr-x  2 105 109 4096 Jul  7  2018 postgres_backup
drwx------ 20 105 109 4096 Jun  6 17:29 postgres_data
drwx------ 19 105 109 4096 Jun  6 16:56 postgres_data_new
drwxrwsr-x  5 105 109 4096 Jun  6 17:29 postgres_run
drwxr-xr-x  2 106 110 4096 Jun  9 14:10 redis_data

안녕하세요,

저희도 비슷한 상황에 처해 있지만, 스탠드얼론(standalone) 설정을 사용하고 있습니다. shared/standalone/log/var-log/에는 아무 파일도 표시되지 않지만, 컨테이너에 진입하면 동일한 결과를 확인할 수 있습니다:

root@pulp-discourse-iptools:/var/www/discourse# tail -n 3 /var/log/postgres/current
2021-10-13 18:33:04.027 GMT [917] LOG:  skipping missing configuration file "/shared/postgres_data/postgresql.auto.conf"
2021-10-13 18:33:04.028 UTC [917] FATAL:  data directory "/shared/postgres_data" has wrong ownership
2021-10-13 18:33:04.028 UTC [917] HINT:  The server must be started by the user that owns the data directory.
root@pulp-discourse-iptools:/var/www/discourse# ls -lan /shared
total 8
drwxr-xr-x 12    0   0  178 Oct 13 18:01 .
drwxr-xr-x 56    0   0  167 May 10  2020 ..
drwxr-xr-x  3 1000  33   21 Apr  3  2019 backups
drwxr-xr-x  4    0   0   34 Apr  3  2019 log
drwxr-xr-x  2  106 110    6 Apr  3  2019 postgres_backup
drwx------ 20  105 109 4096 Oct 13 17:57 postgres_data
drwx------ 19  105 109 4096 Oct 13 18:02 postgres_data_new
drwxrwsr-x  4  105 109   60 Oct 13 17:56 postgres_run
drwxr-xr-x  2  108 111   41 Oct 13 18:26 redis_data
drwxr-xr-x  4    0   0   44 Apr  3  2019 state
drwxr-xr-x  4 1000  33   37 Oct 13 18:26 tmp
drwxr-xr-x  4 1000  33   38 Apr  3  2019 uploads

하지만 여전히 이상해 보입니다:

root@pulp-discourse-iptools:/var/www/discourse# ls -alF /shared | grep postgres_
drwxr-xr-x  2 postgres    postgres    6 Apr  3  2019 postgres_backup/
drwx------ 20 Debian-exim ssh      4096 Oct 13 18:53 postgres_data/
drwx------ 19 Debian-exim ssh      4096 Oct 13 18:02 postgres_data_new/
drwxrwsr-x  4 Debian-exim ssh        60 Oct 13 17:56 postgres_run/

아프기보다 안전해야 하므로, app.yml에서 "templates/postgres.10.template.yml"로 되돌려 놓고 현재는 이전 인스턴스를 다시 실행하는 데만 집중하고 있습니다.

https://github.com/discourse/discourse_docker.git의 main 브랜치로 전환한 후 최신 커밋을 사용하고 있다는 점을 공유하는 것이 도움이 될 것 같습니다. 하지만 재빌드(rebuild)에 실패했으므로, 이전 이미지를 시작할 때 이것이 영향을 미치지 않을 것으로 생각되는데 맞습니까?

이 상황을 해결하는 방법에 대해 아이디어가 있는 분이 계신다면 매우 감사하겠습니다. 그렇지 않다면 추가 보고를 위해 다시 돌아올 수 있습니다.

감사합니다,
Andreas.

다시 인사드립니다.

@noezDE 님의 조언(Update failed (postgresql) - #8 by noezDE)을 따랐더니(정말 감사합니다!) 이 상황을 복구할 수 있었습니다.

이제 사이트가 다시 정상적으로 실행되고 있으며, 다시 업그레이드를 시도해 볼 것입니다.

정중히,
Andreas.


복구 절차

처음에는 다음 명령을 실행하여 진전이 있었습니다.

chown -R postgres /shared/postgres_data
sv restart postgres

그 후 로그에 다음과 같은 메시지가 나타났습니다.

2021-10-13 18:52:12.437 UTC [3357] FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied

그래서 과감하게 다음 명령을 실행했습니다.

chown -R postgres:postgres /shared/postgres_*
sv restart postgres

Voilà(이제 끝났습니다).

"templates/postgres.template.yml"을 다시 사용해 한 번 더 시도해 보았더니, 모든 과정이 매우 순조롭게 진행되었고 PostgreSQL 10에서 PostgreSQL 13으로의 업그레이드도 성공적으로 완료되었습니다. 이 훌륭한 소프트웨어를 개발해 주신 Discourse 팀 전체에 다시 한번 감사드립니다.