Postgres DB를 중앙 DB 서버로 이전: 빌드 오류

안녕하세요,
현재 고전적인 두 컨테이너 구성(웹 전용 컨테이너와 데이터 컨테이너 분리)에서 데이터베이스가 Docker 컨테이너 외부의 중앙 데이터베이스 서버에 호스팅되는 구성으로 마이그레이션하고 있습니다.

중앙 데이터베이스는 백업 파일에 포함된 dump.sql 파일로부터 생성되었습니다. docker compose의 web_only.yaml 파일에는 다음과 같은 설정이 사용되고 있습니다.

중앙 postgres 데이터베이스 연결

DISCOURSE_DB_SOCKET: ‘’
DISCOURSE_DB_USERNAME: discourse
DISCOURSE_DB_PASSWORD: xxxx
DISCOURSE_DB_HOST: 10.10.10.xx
DISCOURSE_DB_NAME: discourse

web_only 빌드过程中 다음과 같은 오류가 발생합니다:

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 741 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.

데이터베이스 호스트는 위 정보로 접근 가능합니다. 여기서 무슨 일이 일어나고 있는지 아이디어가 있을까요? 표준 데이터베이스 컨테이너를 사용한 동일한 빌드는 성공적으로 완료됩니다.

서버에서 원격 데이터베이스에 접근할 수 있는지 확인해 보셨나요? 현재는 접근이 안 되는 것으로 보입니다. 웹 서버 머신에서 데이터베이스 포트에 telnet으로 연결해 볼 수 있나요?

Jay님,

Falco의 스레드(Configure Discourse to use a separate PostgreSQL server)를 따라 진행했습니다. VM에서 데이터베이스 서버에 접근할 수 있습니다:

root@docker2:/var/discourse# pg_isready -d discourse -h 10.10.10.18 -p 5432 -U discourse    
10.10.10.18:5432 - Verbindungen werden angenommen

(연결이 허용됩니다)

web_only.yml 파일의 DB 이름, 사용자 이름 및 비밀번호도 정확합니다. 빌드 오류는 다음과 같습니다.

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process:
:Status: pid 829 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migra
te'"]}
bootstrap failed with exit code 1

저는 Ruby 전문가가 아니므로, 여기에 표시되는 오류부터 디버깅하는 데 도움이 필요합니다.

감사합니다, Thommie

그 경우:

어떤 플러그인을 사용 중이신가요? AI 플러그인을 사용 중이신가요?

어떤 버전의 postgres를 사용 중이신가요?

  • PostgreSQL 13.12
  • AI 플러그인 없음
  • 플러그인:
cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-shared-edits.git
          - git clone https://github.com/discourse/discourse-chat-integration
          - git clone https://github.com/discourse/wp-discourse
          - git clone https://github.com/discourse/discourse-openid-connect
          - git clone https://github.com/discourse/discourse-calendar
          - git clone https://github.com/discourse/discourse-data-explorer
          - git clone https://github.com/paviliondev/discourse-events
          - git clone https://github.com/paviliondev/discourse-locations
          - git clone https://github.com/discourse/discourse-reactions
          - git clone https://github.com/discourse/discourse-chat
          - git clone https://github.com/discourse/discourse-voting.git
          - git clone https://github.com/discourse/discourse-user-notes.git
          - git clone https://github.com/discourse/discourse-solved.git
          - git clone https://github.com/discourse/discourse-footnote.git
          - git clone https://github.com/discourse/discourse-docs.git
          - git clone https://github.com/discourse/discourse-docs-card-filter.git
          - git clone https://github.com/discourse/discourse-assign.git
          - git clone https://github.com/discourse/discourse-templates.git
          - git clone https://github.com/discourse/discourse-saved-searches.git
          - git clone https://github.com/discourse/discourse-tooltips
          - git clone https://github.com/nathan-nz/discourse-wikified-posts
          - git clone https://github.com/discourse/discourse-post-voting.git
          - git clone https://github.com/discourse/discourse-encrypt.git
          - git clone https://github.com/discourse/discourse-zoom.git
          - git clone https://github.com/discourse/discourse-spoiler-alert.git
          - git clone https://github.com/discourse/discourse-category-experts.git

?

백트레이스(Backtrace)의 정확한 오류 메시지가 문제의 원인을 정확히 알려줄 것입니다 :smile:

데이터 컨테이너를 폐기할 계획인가요?

에러 코드:

> FAILED
> --------------------
> Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 816 exit 1>
> Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
> exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
> bootstrap failed with exit code 1

가능하다면, 새 시스템에서는 데이터가 도커 DB가 아닌 중앙 DB에서 가져와야 합니다.

이 값을 unset(미설정) 상태로 두는 대신 빈 값으로 설정하는 것이 문제를 일으키지는 않을지 궁금합니다.

어쨌든, 전체 출력을 게시해 주세요.

./launcher rebuild web_only

실행 후 전체 빌드 로그입니다.

web_only_build.zip (9.4 KB)

YAML 파일

web_only.zip (2.4 KB)

DISCOURSE_DB_SOCKET: ‘’ 값에 관해서는, 원격 연결을 사용하고 있으므로 두 경우(도커화 된 데이터 또는 원격 데이터) 모두에서 소켓 값은 관련이 없을 것으로 추정됩니다.

오류는 빌드 로그의 더 위쪽에 있었습니다:

…
docker_manager is already at latest compatible version
wp-discourse is already at latest compatible version

I, [2023-11-10T21:08:17.388213 #1]  INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
Plugin name is 'discourse-topic-voting', but plugin directory is named 'discourse-voting'
rake aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  permission denied for table users (ActiveRecord::StatementInvalid)

좋습니다! 데이터베이스 연결은 정상적으로 이루어지고 있으며, 데이터베이스 권한을 조정해야 하는 문제입니다.

음, 이상하네요. discourse 데이터베이스 사용자는

postgres=# GRANT ALL ON DATABASE discourse TO discourse;

이 권한을 중앙 PostgreSQL 서버에서 가지고 있습니다. 이 역할을 위해 다른 것이 필요한가요?

기존 테이블에는 영향을 주지 않습니다.

아마도 다음과 같은 방식으로 처리할 수 있습니다:

ALTER DATABASE "discourse" OWNER TO "discourse";

또는:

ALTER DEFAULT PRIVILEGES IN SCHEMA "public" GRANT ALL ON TABLES TO "discourse";

postgres 로그에서도 어떤 작업이 실패하고 있는지 더 자세히 확인할 수 있습니다.

… 알겠습니다, 여기에도 권한 문제가 있는 것 같습니다. /var/log/postgresql/postgresql-13-main.log 파일을 확인해 주세요:

2023-11-10 22:07:58.371 UTC [196127] postgres@postgres STATEMENT:  ALTER DEFAULT PRIVILEGES IN SCHEMA 'public' GRANT ALL ON TABLES TO 'discourse';
2023-11-10 22:10:18.270 UTC [196160] discourse@discourse ERROR:  permission denied for table site_settings
2023-11-10 22:10:18.270 UTC [196160] discourse@discourse STATEMENT:  SELECT name, data_type, value FROM site_settings
2023-11-10 22:10:18.313 UTC [196160] discourse@discourse ERROR:  permission denied for table users
2023-11-10 22:10:18.313 UTC [196160] discourse@discourse STATEMENT:  SELECT COUNT(*) FROM (SELECT 1 AS one FROM "users" LIMIT 20) subquery_for_count

역시 늘 그랬듯이 '8계층 문제’였습니다 :smiling_face_with_tear:

postgres에 이미 discourse 데이터베이스가 있었지만, discourse 사용자/역할에 필요한 모든 권한이 부여되어 있지 않았습니다. 그리고 mariadb와 postgres 간의 몇 가지 중요한 ‘동작상’ 차이점을 놓치고 있었습니다 …

이제 사용자, 데이터베이스, 사용자/역할에 대한 권한을 모두 다시 생성했습니다. (이 사용자가 미래에 생성할 테이블에 적용하기 위해 ALTER DEFAULT PRIVILEGES FOR ROLE discourse IN SCHEMA public GRANT ALL ON TABLES TO "discourse"; 포함)

빌드가 완료되었고, 원격 postgres 서버와 함께 인스턴스가 정상적으로 실행되고 있으므로, 이전 인스턴스의 백업을 가져오는 준비가 끝났습니다.