How to Set Up a Free PostgreSQL Database on Heroku

Let’s explore how we can quickly set up a small Postgres instance in Heroku for our personal projects.

Heroku intended this free Hobby Tier to be used for “proof of concepts, MVPs, and personal projects”.

By using this free tier, we are limited in the following:

  • Enforced row limits of 10,000 rows
  • Maximum storage of 1GB
  • Maximum of 20 connections
  • No in-memory cache: The lack of an in-memory cache limits performance, because the data can’t be accessed on low-latency storage
  • No fork/follow support: Fork and follow, used to create replica databases and leader-follower setups, are not supported
  • No Expensive Queries support
  • Expected uptime of 99.5% each month
  • Unannounced maintenance and database upgrades
  • No Postgres logs
  • No additional credentials

1. Log into Heroku

First, we’ll need to go to Heroku’s Login Page to either login or sign up for an account.

We’ll be brought to our Heroku Dashboard, listing all of our Heroku apps.

2. Create a new app

We want to create a new app.

  • Select NewCreate new app
  • Under App name, type in a name such as project-name-db

After creating the new app, we’ll be brought to the app page.

3. Attach PostgreSQL database

Time to create the database.

  • Head over to the Resources tab.
  • In the Add-ons search bar, search Heroku Postgres
  • Under Plan name, select the Hobby Dev - Free plan

After confirming, we’ll be brought back to the Resources tab.

4. Get database credentials

Next, we need to get the database credentials and connection URL to make calls to this database.

  • In Resources, select Heroku Postgres. It will open the Heroku Data Dashboard.
  • In the Data Dashboard, select the Settings tab
  • Select View Credentials

These credentials (i.e. Host, Database, User, Port, Password, etc.) are needed to connect to the database from our frontend.