Heroku - 8 Heroku postgre part 1
Welcome to this introductory lesson on Heroku Postgres. Postgres is a database add-on, more precisely a relational database, which means you can link data together and create dependencies between records. That relationship management is what mainly differentiates Postgres from non-relational databases like MongoDB. Postgres is known for its high scalability: it delivers good performance both on small tables and on tables with millions of rows, which is why PostgreSQL is often called the Swiss army knife of databases, suitable for small projects as well as large enterprise ones.
This add-on is provided directly by Heroku. In this course we will start with the installation and setup of Postgres on Heroku, get an overview of the Heroku Postgres dashboard, install the extra tools needed to manage the database, and finish with a simple table manipulated through code. The code stays intentionally simple so the lesson remains accessible even without prior database knowledge.
Installing Postgres on Heroku
Inside the application page, go to Resources, search for Heroku Postgres and add it using the free tier. Once installed, open the Config Vars section: Heroku has automatically created a variable named DATABASE_URL. It contains the connection information for the database and acts as its credentials. This variable will be used by the application code to connect to the database.
Exploring the Heroku Postgres dashboard
Open the Postgres dashboard and start with the Overview tab, where you can see information related to the database: the plan, the PostgreSQL version used, the creation date and the maintenance window that tells you when updates are applied. The Rollback feature is useful when data is corrupted: you can return the database to a previous point in time. The Usage panel shows the current number of connections and the maximum allowed simultaneously.
On the durability side, you can take manual backups, but since manual backups may not be enough in terms of safety, Heroku Postgres also provides continuous protection that regularly copies the database. These backups can be restored later. In Settings you can retrieve the credentials, which is useful when an external tool needs to access the database, and you can also destroy the database, which deletes all data. Finally, there is a Dataclips feature: it is read-only, so you can run queries like SELECT but cannot insert, update or delete from there. You give the clip a title, choose which database to target and then write your query.
One important limitation: you cannot manipulate the Heroku Postgres database directly from the dashboard. We therefore need an external tool installed locally to connect to the database and modify it, which is what we will set up in the next lesson.