Getting started on web application with a Postgres database on Heroku

Getting started on web application with a Postgres database on Heroku

Introduction to using Heroku PostgreSQL with Heroku CLI

Heroku has three managed data services that can handle the database on your application. These are Heroku Postgres, Heroku Redis and Apache Kafka on Heroku. These services have a price range that varies from free to paid, depending on which pricing options you choose.

In this article, we are going to go through step by step, how to deploy a web application and then attach a PostgreSQL database to it.

First, let us understand what is Heroku, what is PostgreSQL, and how these two can work together to make your application database smooth, efficient, and easy to work with.

So...

Heroku is a platform as a service (When you purchase/rent resources from cloud providers,use them over the internet, and pay according to how much you use) company that provides developers with a faster and efficient way to create, deploy, scale, and manages applications in the cloud. Heroku supports multiple languages such as Ruby, Python, Scala, Node.js, PHP, Go, Java, and Clojure. To make PaaS even better, Heroku follows three principles...

  • Developer Centric. This is, Heroku keeps developers at its center. It is made by developers, for developers

  • App Centric. It focuses on ways to get the application in front of the user, faster and hassle-free.

  • Production Centric. Heroku focuses on every step of the application life-cycle, from build to deployment, and scaling. It ensures that every step in between is easy and efficient.

Cool, right?

Well, also known as Postgres, this is a powerful open-source object-relational management system. It is best-known for its commitment to data integrity, reliability, and extensibility. It uses an extent of SQL language and many other powerful features to store and work with complicated workloads.

Heroku Postgres is a fully managed database backend service for developers. It provides nine cool features and tools, all of them being forks, followers, dataclips, trusted data integration, continuous protection, straightforward rollbacks, automated health checks, high availability, security compliance, data encryption, and Heroku Postgress via mutual LTS. You can find more information about these tools here

  • Heroku account. You can sign up here

  • Heroku CLI. You can download it here

  • Git. You can download it here.

  • Github account. You can sign up here.

  • And and a web application on your local repository you wish to deploy to Heroku. I will be using a java web app for this demonstration.

  • I will be using Ubuntu 18.04 LTS as my operating system.

Ok. Ready?

$ heroku login -i
$ cd /Downloads/sampleapp/

Because I am running a java app, I will run...

$ mvn clean install

You can test the application locally on Heroku with

$ heroku local web
$ heroku create
$ git push heroku master

If that does not work out for you, try..

$ git push heroku main
$ heroku pg:info
$ heroku addons:create postgres
$ heroku open

This is the Heroku dashboard. Click on the name of your application app1.png

Click on the Heroku Postgres addon that you just created app2.png

Go to settings

app3.png

Click on view credentials button app4.png

View your database credentials app5.png

You can use these credits to login onto your local PostgreSQL to connect your local database and your Heroku database.

$ heroku pg:psql
$ \q

To learn more about the Heroku platform, you can experiment more with the free resources. learn more on this link. To learn more about PostgreSQL, click this link. And if you are curious about Heroku Postgres, do not worry here is a full Heroku Postgres documentation.

Did you find this article valuable?

Support Thandi Writes by becoming a sponsor. Any amount is appreciated!