1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00
Files
til/heroku/connect-to-a-database-by-color.md
2024-09-26 08:47:31 -05:00

964 B

Connect To A Database By Color

All of your PostgreSQL databases in Heroku are given attachment names that use a random color. This might be pink, brown, cobalt, etc. And the attachment names then look like HEROKU_POSTGRESQL_PINK, HEROKU_POSTGRESQL_BROWN, HEROKU_POSTGRESQL_COBALT, etc.

We can connect to a Heroku-managed PostgreSQL instance from the command-line like so:

$ heroku pg:psql --app my-app

This is going to connect to the default database which is the one with the DATABASE_URL attachment.

There are lots of instances where we may have other databases besides the primary (e.g. let's say we have a read replica follower). If we want to connect to that one, we can do so by color.

If that database's attachment is HEROKU_POSTGRESQL_IVORY, then we'd connect to it like so:

$ heroku pg:psql ivory --app my-app

source