Postgres DBを中央DBサーバーに移行:ビルドエラー

こんにちは。

現在、古典的な2コンテナセットアップ(Webのみとデータコンテナを分離)から、データベースが中央データベースサーバー(Dockerコンテナ内ではない)でホストされるセットアップに移行中です。

中央データベースは、バックアップファイルに含まれるdump.sqlから作成されました。docker compose web_only.yamlは以下を使用します。

  ## connect to central postgres database
  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.

データベースホストにはこれらのデータでアクセスできます。何が起こっているのか、何かアイデアはありますか?標準のデータベースコンテナを使用した同じビルドは正常に完了します。

リモートデータベースがサーバーから利用可能であることを確認しましたか?利用できないようです。Webサーバーマシンからデータベースポートにtelnetできますか?

ジェイ様

Configure Discourse to use a separate PostgreSQL server の Falco のスレッドに従いました。データベースサーバーは 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 &amp;&amp; su discourse -c 'bundle exec rake db:migrate' failed with return #&lt;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 の専門家ではないため、ここで表示されるエラーからのデバッグについて、いくつか助けが必要です。

では、トミー

その場合:

どのプラグインをお持ちですか?AI プラグインはありますか?

PostgreSQL のバージョンは何ですか?

  • 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

スタックトレース内の正確なエラーメッセージが問題の原因を正確に教えてくれます :smile:

データコンテナを廃止する予定ですか?

「いいね!」 1

エラーコード:

> 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

新しいシステムでは、可能な限り、データはDocker DBではなく中央DBから取得されるものとします。

この値を未設定ではなく空白に設定すると問題が発生するのではないかと疑問に思っています。

いずれにせよ、完全な出力を投稿してください。

「いいね!」 1

./launcher rebuild web_only の後の完全なビルドログ

web_only_build.zip (9.4 KB)

YAML

web_only.zip (2.4 KB)

DISCOURSE_DB_SOCKET: 「」について:リモート接続を使用しているため、ドックされたデータまたはリモートデータのいずれの場合でも、ソケット値は関連しないと推測します。

「いいね!」 1

エラーはビルドログのさらに上にありました。

…
docker_manager は既に最新の互換性のあるバージョンです
wp-discourse は既に最新の互換性のあるバージョンです

I, [2023-11-10T21:08:17.388213 #1]  INFO -- : cd /var/www/discourse & su discourse -c 'bundle exec rake db:migrate'
プラグイン名が 'discourse-topic-voting' ですが、プラグインディレクトリの名前が 'discourse-voting' です
rake aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  table users に対する権限がありません (ActiveRecord::StatementInvalid)

ということで、良いニュースです!接続は正常に行われており、DB権限を調整する必要があります。

「いいね!」 2

うーん、奇妙ですね。ディスコースデータベースのユーザーには、

postgres=# GRANT ALL ON DATABASE discourse TO discourse;

中央のPostgresサーバーにあります。このロールには他に何か必要ですか?

既存のテーブルには影響しません。

手っ取り早く、おそらく:

ALTER DATABASE "discourse" OWNER TO "discourse";

または:

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

PostgreSQLのログにも、どの操作が失敗しているか詳細が表示されるはずです。

「いいね!」 4

… ok ok、どうやらここにも権限の問題があるようです。/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

OK、いつものように「レイヤー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サーバーで正常に動作しています。そのため、古いインスタンスからのバックアップのインポート準備ができました。

「いいね!」 4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.