# DB\_USERまたはmultisite.ymlの値ではなく、ユーザーディスコースを使用したマルチサイトバックアップ

**URL:** <https://meta.discourse.org/t/multisite-backup-using-user-discourse-rather-than-db-user-or-value-from-multisite-yml/320218>\
**Category:** Bug\
**Tags:** unsupported-install\
**Created:** [2024 年 8 月 5 日午後 5:01 UTC](https://meta.discourse.org/t/multisite-backup-using-user-discourse-rather-than-db-user-or-value-from-multisite-yml/320218 "2024-08-05T17:01:32Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2024 年 8 月 5 日午後 5:01 UTC](https://meta.discourse.org/t/multisite-backup-using-user-discourse-rather-than-db-user-or-value-from-multisite-yml/320218/1 "2024-08-05T17:01:32Z")

</div>

編集/要約： `ActiveRecord::Base.connection_pool.db_config.configuration_hash` には、`username` ではなく `user` にユーザー名が含まれていますが、Discourse は `username` で検索しています。

簡単なPR： [FIX: backup\_restore.rb wants db user from user, not username by pfaffman · Pull Request #28229 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/28229)

…

マルチサイトインスタンスで Digital Ocean のホストされている postgres を使用しています。正常に動作していますが、バックアップしようとすると、次のエラーが発生します。

```plaintext
[2024-08-05 16:13:31] pg_dump: error: connection to server at "private-forum-cluster-postgresql-prod-do-user-1230.j.db.ondigitalocean.com" (10.11.1.6), port 25060 failed: FATAL: password authentication failed for user "discourse"

```

しかし、ユーザーは `discourse` ではありません。他の場所でも、`ActiveRecord::Base.connection_pool.db_config.configuration_hash` や `BackupRestore.database_configuration` (これらを ` RAILS_DB=sitename rails c` で実行した場合) を含む、正しいユーザーを使用しています。PG\_USER は環境変数で設定されていません (私が見る限り)。

これが原因のようです：

> <https://github.com/discourse/discourse/blob/main/lib/backup_restore.rb#L138>

コンテナ内でこれを編集しました (当時良い考えだと思った DISCOURSE\_DB\_USER から取得するように) 、バックアップは現在機能しています。`multisite.yml` から接続情報を取得できるのかどうかはわかりませんが、`DB_USER` を無視するのは間違っているように思えます。

~~それとも、他の皆がやっているように、ユーザーを `discourse` にすべきなのでしょうか？~~

編集：いや。

`config['username']` は `config['user']` であるべきです。

```plaintext
    config = ActiveRecord::Base.connection_pool.db_config.configuration_hash

```

はこれを返します！

```plaintext
   
=> {:adapter=>"postgresql",
 :database=>"theDatabase",
 :pool=>25,
 :port=>25060,
 :timeout=>5000,
 :host=>"private-forum-cluster-postgresql-prod-do-user-123-0.j.db.ondigitalocean.com",
 :user=>"theCurrentUsername",
 :password=>"supersecret",
 :host_names=>["forum.example.com"],
 :db_key=>"mydb",
 :prepared_statements=>false}

```

なので

```plaintext
    config["username"] || username || ENV["USER"] || "postgres",

```

は

```plaintext
    config["user"] || username || ENV["USER"] || "postgres",

```

であるべきです。

---

_[View the full topic](https://meta.discourse.org/t/multisite-backup-using-user-discourse-rather-than-db-user-or-value-from-multisite-yml/320218)._
