Heroku deployment failing due to bad PG connection

35 Views Asked by At

I've been running my Rails application on Heroku with a PostgreSQL database for years without any issues. However, recently, I've started encountering a connection timeout error, and I'm not sure what's causing it.

This is from my heroku logs --tail

PG::ConnectionBad (connection to server at "ec2-50-17-21-170.compute-1.amazonaws.com" (50.17.21.170), port 5432 failed

Troubleshooting Steps Taken:

  • Checked the PostgreSQL server status, and it's running.
  • Verified the database connection configuration in config/database.yml.
  • No recent changes to the application code related to database connection.
  • I have also reached out to Heroku, hopefully they might be able to assist but I wanted to put the question out here as well.

Most of the other things people have posted about this issue seem related to people who are deploying their app for the first time. However, mine has been running without issue for years, so I am curious why I am suddenly experiencing this.

Questions:

  • What could be causing this sudden connection timeout issue?
  • Are there any specific steps I should take to troubleshoot further?
  • Are there known issues with the versions of PostgreSQL, Rails, or other gems used in my application?
  • Why is this happening now?

Additional Context:

  • The database server is hosted on Heroku (AWS RDS).
  • The application is deployed on Heroku.
  • The PostgreSQL gem version is 1.2.3, and Rails version is 6.0.4.4.
1

There are 1 best solutions below

0
Ama On

Just an update in case people stumble upon this later. I reached out to Heroku, and it took a second for them to get back to me, but they suggested looking into rotating my credentials.

I looked at this page, and simply ran the command:

heroku pg:credentials:rotate DATABASE -a example-app

You should obviously substitute example-app with your own app name. Please note, after running this command, you will have to confirm the action by typing your app name, i.e. example app.

And this did the trick!