Psql is the terminal application that ships with Postgres. It enables us to run queries and administer our Postgres databases from the command line. With Heroku, you can either use the Heroku CLI to start up a psql session or you can connect to your database using only psql. In this recipe, you'll be introduced to both methods.
To start, let's open up a terminal:
We can quickly start up a psql session through the Heroku CLI by running the
pg:psql
command:$ heroku pg:psql
By default, it will connect to the database in our
DATABASE_URL
config variable. If we want to connect to a different database, we need to specify the name:$ heroku pg:psql ORANGE
We don't have to use the Heroku CLI to connect to our database. If we'd like, we can use plain psql from the command line. We can get our credentials from the
DATABASE_URL
configuration variable, and then pass them to thepsql...