I have a Ruby on Rails app with a posgresql database running on Heroku. In my config/database.yml
file, I have the following entry
production: &deploy
encoding: utf8
min_messages: warning
pool: <%= [Integer(ENV.fetch("MAX_THREADS", 5)), Integer(ENV.fetch("DB_POOL", 5))].max %>
timeout: 5000
url: <%= ENV.fetch("DATABASE_URL", "") %>
so I am expecting Heroku to handle the database setup and credentials.
The app has been operating successfully for several years. Since Heroku database maintenance, when I try to run the app, I get an error message FATAL: password authentication failed for user: "xyz"
. If I do heroku config
the DATABASE_URL is of the form postgres://xyz:some_long_hash
, which seems to imply that xyz
is the correct username.
However if I go into heroku web portal, I can view the database credentials, the listed user name is not xyz
but some other user name, and there is a very long password.
How do I fix this?
Based on this article from Heroku Support, I needed to rotate the credentials manually. I did this with
heroku pg:credentials:rotate
which worked.
Evidently with with the Hobby/Mini/Tier, when Heroku does maintenance, this problem can occur. You can check if the credentials are valid with
pg:credentials:url -a <appname>
Based on a comment by max, I will be deleting from config/database.yml
the line
url: <%= ENV.fetch("DATABASE_URL", "") %>
and replacing it with a comment to the effect that heroku chooses the url and stores it as config variable DATABASE_URL
.