수정/Tl;dr: ActiveRecord::Base.connection_pool.db_config.configuration_hash에는 username이 아닌 user 키에 사용자 이름이 포함되어 있지만, 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_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",