A One Liner to Connect to Heroku’s Postgres DB From psql

I just figured this out and felt like sharing / recording it so I don’t have to figure it out again.

I wanted to connect to my postgres DB directly from psql, rather than using heroku’s command line shortcut “heroku pg:psql”.

So anyway here’s a quick one liner to get the credentials for your DB and connect directly using psql.

heroku pg:credentials DATABASE_URL -a <your app name here> | sed -n 2p | xargs psql