Book Image

Heroku Cookbook

By : Mike Coutermarsh
Book Image

Heroku Cookbook

By: Mike Coutermarsh

Overview of this book

Heroku is a Platform as a Service that enables developers to rapidly deploy and scale their web applications. Heroku is designed for developer happiness, freeing developers from doing system administrative tasks such as configuring servers and setting up load balancers. Developers are able to focus on what they do best, building web applications, while leaving the details of deployment and scaling to the experts at Heroku. This practical guide is packed with step-by-step solutions to problems faced by every production-level web application hosted on Heroku. You'll quickly get comfortable with managing your Heroku applications from the command line and then learn everything you need to know to deploy and administer production-level web applications.
Table of Contents (17 chapters)
Heroku Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Connecting to Heroku Postgres from psql


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.

How to do it…

To start, let's open up a terminal:

  1. We can quickly start up a psql session through the Heroku CLI by running the pg:psql command:

    $ heroku pg:psql
    

    Note

    To exit the psql session, type \q and hit Enter or press Ctrl + D.

  2. 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
    
  3. 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 the psql...