EDIT/Tl;dr: ActiveRecord::Base.connection_pool.db_config.configuration_hash
has the username in user
, not username
, but Discourse is looking for it in username
.
…
I’ve got a multisite instance using Digital Ocean’s hosted postgres. It’s working fine but when I try to backup, I get an error that
[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"
But the user is not discourse
. It’s using the correct user other places, including ActiveRecord::Base.connection_pool.db_config.configuration_hash
and BackupRestore.database_configuration
(when I run those commands in RAILS_DB=sitename rails c
). PG_USER is not set in the environment (that I can see).
It looks ike this is to blame:
I edited it in the container (to pull it from DISCOURSE_DB_USER, which seemed like a good idea at the time) and the backup works now. I don’t know if you’re supposed to be able to pull connection info out of multisite.yml
or not, but ignoring DB_USER
seems wrong.
Or maybe I should just make the user be discourse
like I guess everyone else must be doing?
EDIT: Wait. No.
config['username']
should be config['user']
config = ActiveRecord::Base.connection_pool.db_config.configuration_hash
returns this!
=> {: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}
So
config["username"] || username || ENV["USER"] || "postgres",
should be
config["user"] || username || ENV["USER"] || "postgres",