外部Postgresインスタンスへの移行時にエラーが発生しました

デフォルトの自己完結型設定で discourse-docker を使用してフォーラムをセットアップしました。個別の postgres サーバーを使用するように切り替える必要があります。

バックアップを実行し、app.yml を変更して再構築し、CLI を介してバックアップから復元しようとしました。復元は失敗し、復元は正しいホストを使用して postgres にアクセスしているように見えますが、設定したポート (9432) ではなくデフォルトのポート (5432) を使用していました。

エラー:

psql: error: connection to server at "[REDACTED HOST]" ([REDACTED IP]), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
EXCEPTION: psql failed: 	Is the server running on that host and accepting TCP/IP connections?
/var/www/discourse/lib/backup_restore/database_restorer.rb:92:in `restore_dump'
/var/www/discourse/lib/backup_restore/database_restorer.rb:26:in `restore'
/var/www/discourse/lib/backup_restore/restorer.rb:51:in `run'
script/discourse:149:in `restore'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/base.rb:584:in `start'
script/discourse:290:in `<top (required)>'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/cli/exec.rb:58:in `load'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/cli/exec.rb:58:in `kernel_load'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/cli/exec.rb:23:in `run'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/cli.rb:451:in `exec'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/cli.rb:34:in `dispatch'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/cli.rb:28:in `start'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/exe/bundle:28:in `block in <top (required)>'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/exe/bundle:20:in `<top (required)>'
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
Trying to rollback...
Rolling back...
Cleaning stuff up...
Dropping functions from the discourse_functions schema...
Removing tmp '/var/www/discourse/tmp/restores/default/2024-01-17-201724' directory...
Unpausing sidekiq...
Marking restore as finished...
Notifying 'system' of the end of the restore...
Finished!
[FAILED]

設定:
app.yml の templates: の下で、- "templates/postgres.template.yml" をコメントアウトしました。

また、env の下に以下を追加しました。

  DISCOURSE_DB_USERNAME: [REDACTED]
  DISCOURSE_DB_PASSWORD: [REDACTED]
  DISCOURSE_DB_HOST:  [REDACTED]
  DISCOURSE_DB_PORT: 9432
  DISCOURSE_DB_NAME: [REDACTED]

再構築した際に、新しい空白のサイトが生成されましたか?もしそうでない場合は、何らかの問題が発生している可能性があります。

コンテナ内から psql <データベースを指定するいくつかのスイッチ> でデータベースにアクセスできますか?

コンテナ内で set|grep DB を実行した場合、環境変数は表示されますか?

はい、3つすべてに該当します。新しい空白のサイトが生成され、正しいデータベースに接続されます。環境変数はgrepで見つけられ、コンテナ内から手動でDBに接続できます。

リストアスクリプトが環境変数を尊重しないという可能性はごくわずかです(しかし、それ以外はすべて尊重していますか?)。それを確認するには、コードを確認するか、UXからリストアを試みてください。UXからリストアできる場合は、これを#bugに移動できると思います。

UX経由でも復元を試みましたが、同じエラーが発生しました。

それなら、次にコードを確認すると思います。

特に他のすべてで動作しているのが奇妙です。

rails コンソールに入り、次の値を示してください。

BackupRestore.database_configuration
BackupRestore::DatabaseRestorer.psql_command

例:

→ rails c
Loading development environment (Rails 7.0.8)
[1] pry(main)> BackupRestore.database_configuration
=> #<struct BackupRestore::DatabaseConfiguration
   host=nil,
   port=nil,
   username="michael",
   password=nil,
   database="discourse_development">

[2] pry(main)> BackupRestore::DatabaseRestorer.psql_command
=> "psql --dbname='discourse_development' --single-transaction --variable=ON_ERROR_STOP=1 --username=michael"
「いいね!」 1

はい、承知いたしました。私が削除した内容はすべて正しいです。ポート番号だけが間違っています。

[1] pry(main)> BackupRestore.database_configuration
=> #<struct BackupRestore::DatabaseConfiguration
   host="[REDACTED]",
   port=5432,
   username="[REDACTED]",
   password="[REDACTED]",
   database="[REDACTED]">
[2] pry(main)> BackupRestore::DatabaseRestorer.psql_command
=> "PGPASSWORD='[REDACTED]' psql --dbname='[REDACTED]' --single-transaction --variable=ON_ERROR_STOP=1 --host=[REDACTED] --port=5432 --username=[REDACTED]"

また、空白のインスタンスは、バックアップからの復元以外はすべてデータベースに接続できることも改めて申し上げます。

ActiveRecord::Base.connection_pool.db_config.configuration_hash

とは何ですか?

「いいね!」 1
[3] pry(main)> ActiveRecord::Base.connection_pool.db_config.configuration_hash
=> {:adapter=>"postgresql",
 :pool=>8,
 :connect_timeout=>5,
 :socket=>"/var/run/postgresql",
 :host=>"[REDACTED]",
 :port=>9432,
 :backup_port=>5432,
 :username=>"[REDACTED]",
 :password=>"[REDACTED]",
 :host_names=>["[REDACTED]"],
 :database=>"[REDACTED]",
 :prepared_statements=>false,
 :idle_timeout=>30,
 :reaping_frequency=>30,
 :advisory_locks=>true}

Ah! さらに、以下を設定する必要があります。

DISCOURSE_DB_BACKUP_PORT: 9432

これでうまくいくはずです。

編集:このデフォルトはしばらくの間有効でしたが、それ以上に困難を引き起こしているようです。

FIX: clear db_backup_port default value by Supermathie · Pull Request #25316 · discourse/discourse · GitHub もこれを解決し、将来の利用者の混乱を避けるはずです。

「いいね!」 2

大変助かります!ありがとうございます!

「いいね!」 1

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