thundrshock
thundrshock

Reputation: 103

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?

Upvotes: 10

Views: 5665

Answers (2)

software_writer
software_writer

Reputation: 4468

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.

Upvotes: 14

Shiva
Shiva

Reputation: 12514

May be attaching the same database to two heroku-apps will better suit you. In this way, pg creds will be auto-managed by heroku.

I am also using this technique. I have one client-facing app and another operation-app sharing the same database instance.

You can either do this using UI or via CLI

see Share database between 2 apps in Heroku

Upvotes: 1

Related Questions