How to set up a free PostgreSQL database on Heroku
Tags: postgres, heroku, database, sql
Published: 2020-02-26 08:01:42

---
title: How to set up a free PostgreSQL database on Heroku
published: true
description: 
tags: PostgreSQL, Heroku, Database, SQL
---

> ⚠️ **Update**: Heroku does not offer hosting free PostgreSQL database any more. Instead, you can [set up a PostgreSQL database for free with Supabase](https://dev.to/prisma/set-up-a-free-postgresql-database-on-supabase-to-use-with-prisma-3pk6).

[Heroku](https://heroku.com/) offers a free plan for hosting PostgreSQL databases. This can be handy if you're getting started with a new project or "just quickly need a hosted database" for experimentation or prototyping.

This guide explains how to quickly setup a free PostgreSQL database on Heroku. You can learn more in the [Heroku Postgres documentation](https://devcenter.heroku.com/categories/heroku-postgres).


## TLDR

In order to create a new database on Heroku, you first need to create an **app** in your personal dashboard. Then you can attach a **Heroku Postgres** instance to it as a **resource**.

## Step 1: Log into Heroku

Navigate your browser to [`https://id.heroku.com/login`](https://id.heroku.com/login) and log in. If you don't have an account yet, you can sign up via the **Sign Up** button below the login form:

![](https://imgur.com/8zSjKZI.png)

## Step 2: Create a new Heroku app

Once you see your personal app dashboard, you can create a new app. If your dashboard is currently empty, you can click the **Create new app** button. Otherwise click the **New** button in the top-right corner and select **Create new app**:

![](https://imgur.com/JnnlOzl.png)

Since you only need the app to get access to your database, the **App name** doesn't really matter and you can choose whatever you want. In the screenshot below, **`get-my-db`** is used as an **App name**:

![](https://imgur.com/Ynscakp.png)

If you want, you can also change the **Region** so that the database is hosted closer to where you are located.

Once you've provided the **App name**, you can click the **Create app** button.

## Step 3: Add a PostreSQL database

To attach a PostgreSQL database to the app you just created, you need to navigate to the **Resources** tab in the header of your newly created app's dahsboard. Then type **Heroku Postgres** into the **Add-ons** search field.

When shown, select the suggested **Heroku Postgres** add-on from the dropdown:

![](https://imgur.com/o5w5st7.png)

The next popup asks you to choose a pricing plan for the database. Select the **Hobby Dev - Free** plan and click **Provision**:

![](https://imgur.com/sKS1b3m.png)

Congratulations, you now created a free PostgreSQL database 🎊

## Step 4: Access the database credentials (and connection URL)

To find the credentials and the connection URL for the PostgreSQL database, you need to navigate to the **Resources** tab in your app's dashboard again and select the **Heroku Postgres** resource:

![](https://imgur.com/m9d07zx.png)

This brings you to the configuration screen of the your PostgreSQL database:

![](https://imgur.com/dfH6svo.png)

Now select the **Settings** tab in the header of that screen:

![](https://imgur.com/0nI2Exv.png)

Here, you can click the **View Credentials** button to see the credentials of your PostgreSQL database:

![](https://imgur.com/u2JmtXU.png)

You can use these credentials to connect to your PostgreSQL database from any PostgreSQL client, e.g. [`psql`](https://www.postgresql.org/docs/9.3/app-psql.html) (CLI), [TablePlus](https://tableplus.com/) or [Postico](https://eggerapps.at/postico/) (GUIs).

For further reading, you can check out the [Heroku Postgres documentation](https://devcenter.heroku.com/categories/heroku-postgres).

If you want to use this database in a Node.js or TypeScript application, be sure to check out [Prisma](https://github.com/prisma/prisma2) as an alternative to traditional ORMs. Get started with Prisma [here](https://pris.ly/d/getting-started).