Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku Permanent Database Credentials

I've decided to save time on the ops side of things and move to Heroku. I'm planning to have a production dyno on Heroku with a postgres database AND another dyno that reads from the same database.

However when I opened the settings of postgres, it said:

Database Credentials
Get credentials for manual connections to this database.

Please note that these credentials are not permanent.
Heroku rotates credentials periodically and updates applications where this database is attached.

What's a good way to go about this?

like image 791
thundrshock Avatar asked Jan 06 '18 05:01

thundrshock


1 Answers

From Heroku Documentation,

Credentials

Do not copy and paste database credentials to a separate environment or into your application’s code. The database URL is managed by Heroku and will change under some circumstances such as:

  • User initiated database credential rotations using heroku pg:credentials:rotate.
  • Catastrophic hardware failure leading to Heroku Postgres staff recovering your database on new hardware.
  • Automated failover events on HA enabled plans.

It is best practice to always fetch the database URL config var from the corresponding Heroku app when your application starts. For example, you may follow 12Factor application configuration principles by using the Heroku CLI and invoke your process like so:

DATABASE_URL=$(heroku config:get DATABASE_URL -a your-app-name) your_process

This way, you ensure your process or application always has correct database credentials.

like image 110
Akshay Khot Avatar answered Sep 19 '22 20:09

Akshay Khot