Sign up for Hasura Newsletter

Installing PostgreSQL

Before we dive in to the core concepts, we will install Postgres on the local machine to try out all the SQL statements given in examples. There are multiple ways to set up Postgres, but for this tutorial we will focus on local development and one Cloud alternative.

Setup Postgres locally using Docker

We can make use of docker-compose to install Postgres locally

Create a new file called compose.yaml and copy the contents below:

version: '3.6'
services:
postgres:
image: postgres:13.3
restart: always
ports:
- "5432:5432"
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgrespassword
volumes:
db_data:

In your terminal, execute the following command:

docker-compose up -d

Now you can check if the above command was successful, by executing the following command:

docker ps

This should give an output which should look something like this:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2aa0954cd3e0 postgres:13.3 "docker-entrypoint.s…" 12 seconds ago Up 5 seconds 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp postgres_1

If the status is up, then Postgres is ready to be connected. In the next step, we will look at how to connect to this instance.

Setup PostgreSQL via Heroku Postgres

Alternatively, you can also set up PostgreSQL via Heroku. Heroku has a free tier Postgres add-on that can be used for quick testing and of course can be later upgraded for production usage.

Head to Heroku Postgres Add-on page and click on Install Heroku Postgres button.

Heroku Postgres Addon

In the next step you will be asked to select an app in your Heroku account to provision the Postgres addon. In case you are new to Heroku or don't have an app created yet, you can head to Heroku Dashboard to create a new app and map that to your Postgres addon in the above step.

Postgres Provisioning

This will provision the database on the app you have selected.

Cloud Hosting Providers for PostgreSQL

For production use cases, there are managed Postgres solutions from various cloud providers.

You can also find the comprehensive list of officially recognised Cloud Providers for hosting PostgreSQL.

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2021 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin