编辑/Tl;dr:ActiveRecord::Base.connection_pool.db_config.configuration_hash 中的用户名在 user 而不是 username 中,但 Discourse 在查找 username。
…
我有一个使用 Digital Ocean 托管的 postgres 的多站点实例。它运行正常,但当我尝试备份时,我收到一个错误,即
[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 不在环境变量中(据我所见)。
它看起来像是这个应该负责:
discourse/lib/backup_restore.rb at main · discourse/discourse · GitHub
我在容器中编辑了它(将其从 DISCOURSE_DB_USER 拉取,当时我认为这是一个好主意),现在备份工作正常。我不知道你是否应该能够从 multisite.yml 中拉取连接信息,但忽略 DB_USER 似乎是错误的。
或者我应该像其他人一样把用户设为 discourse?
编辑:等等。不。
config['username'] 应该是 config['user']
config = ActiveRecord::Base.connection_pool.db_config.configuration_hash
返回这个!
=> {: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}
所以
config["username"] || username || ENV["USER"] || "postgres",
应该是
config["user"] || username || ENV["USER"] || "postgres",