DEV Community

Cover image for Setup Free PostgreSQL on Heroku
Ahmad Mujahid
Ahmad Mujahid

Posted on

Setup Free PostgreSQL on Heroku

Who don't want a free charge hosted database to test an app? I think anyone wants something free to test their app. Especially, a small app. Why do we buy a VPS just for testing a small scale hosted database when there is a free solution like Heroku PostgreSQL.

How To Host A PostgreSQL on Heroku For Free

We will cover step by step to host a PostgreSQL on Heroku. First of all, make sure you are already registered on Heroku. If not, please just register on the website, https://heroku.com. After that, just login the website with your registered account.

Step One : Create an app on Heroku

To create an app in Heroku, you can click button New > Create New App or if you are new in Heroku, you can just click button Create a new app button on your Heroku desktop.

Heroku dashboard

After that, the Create New App page will be shown.

Create New App page

Fill the App name with the name you want until you get a green tick. In my case, I will name it postgresql-app. You can choose your region between United States or Europe to host your database. Then, click Create App. You'll be redirected to the app dashboard page after that.

Step Two : Add PostgreSQL Database.

To add a database to your app, go to Resources on your app dashboard. Then, on the Add-ons, search for Heroku Postgres.

You will get a pop up to submit your order.
Order submission form pop up

Choose Hobby Dev - Free on Plan name select. Then, click Submit Order Form button.

Your database app is successfully created on Heroku! Congrats!

Step Three : Database Credentials (How to obtain it)

Now, you have your database app. But, how to access it? To access your hosted database from your client app, you need some credentials variables such us server URL, port number, username, password, and database name.

Our Heroku Postgres app dashboard

To obtain your database app credentials, click the Heroku Postgres on your app dashboard. You will see the Datastores page like below.

Datastores page

Go to Settings, Click on View Credentials...
Click on View Credentials... button

And, there you have it. You got your database app credential.
Database app credential, I don't blur the Port because 5432 is PostgreSQL default port
You can copy these information to your apps or your database clients to access it.

Bonus : Connect to DBeaver Database Client.

DBeaver is free and open-source database client app that can integrates with various DBMS including PostgreSQL.

DBeaver logo

First of all, you absolutely need to install DBeaver first. You can get it from its website, you can install in Windows, Linux, or MacOS system. I won't cover the installation on this article as it is easy to find the tutorial on the internet if you are confused.

Further, open your installed DBeaver. Click File > New or just type the shortcut CTRL + N. You will get Select a wizard pop up. Select DBeaver > Database Connection. Then, click Next.

Select a wizard pop up

Next, Select SQL > PostgreSQL on Select your database part. Then, click Next.

Select your database

Next, on Connection Settings, copy your database credentials (host, database, user / username, and password) from your Heroku database app to this form. Then, click Finish.

Connection Settings

To connect or check the connection, you can right click to the database on DBeaver Database Navigator, select Connect.

How to connect

If you get PostgreSQL with green tick next to your database name on Database Navigator like in the picture below, that means you are successfully connected to your Heroku PostgreSQL app.

Successful connection

That's it. :)

Top comments (0)