Connecting to Heroku Postgres Databases from Outside of Heroku

Heroku Postgres databases are designed to be used with a Heroku app. However, they are accessible from anywhere and may be used from any application using standard Postgres clients.

To make effective use of Heroku Postgres databases outside of a Heroku application, keep in mind the following:

Heroku app

All Heroku Postgres databases have a corresponding Heroku application. You can find the application name on the database page at data.heroku.com. You do not have to use the Heroku app for application code, but your database is attached to it and holds a config var containing the database URL. This variable is managed by Heroku, and is the primary way we tell you about your database’s network location and credentials.

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:

SSL

Connecting to a Heroku Postgres database from outside of the Heroku network requires SSL. Your client or application must support and enable SSL to connect to a Heroku Postgres database. Most clients will connect over SSL by default, but on occasion it is necessary to set the sslmode=require parameter on a Postgres connection. Note: it is important to add this paramater in code rather than editing the config var directly. Various automated events such as failover can change the config var, and edits there would be lost.

Backups

You can use Heroku Postgres Backups on the enclosing Heroku app in order to get automated backups on your database. Heroku Postgres Backups takes backups of the database pointed at by DATABASE_URL in the Heroku app, so make sure you promote your database: