Learn the basics of Postgres, what it is, how it works, and how to install it on macOS
In this post we will cover some of the basics of using PostgreSQL on macOS. This will include some background about what PostgreSQL is and how it works, installation, creation of databases and basic querying.
PostgreSQL is an open-source Database Management Systems (DBMS). It is a software system which is free to use to store, retrieve, and run queries on data. It serves as an interface between an end-user and a database, allowing users to create, read, update, and delete data in that database.
PostgreSQL is easy to get started with and use, it can also be installed on your local machine which makes it a great way to get to grips with using databases and database querying. Postgres also has sophisticated features to meet more complex needs, such as Multi-Version Concurrency Control and point in time recovery.
We will first cover installation of PostgreSQL. This tutorial covers installation on macOS but there are plenty of resources available for installing via Windows or Linux. We recommend this tutorial. Although each step will be explained, it is best to have some experience using the Terminal to follow along with this tutorial.
The simplest way to download and connect to Postgres is by using Postgres.app.
Postgres.app is a PostgreSQL installation packaged as a Mac app. It has a simple user interface which allows users to easily start and stop postgres and see whether it’s running without needing to use the command line. The app can be downloaded here.
Once you have downloaded the app, you will have a default postgres database with a public schema. To connect with psql, double click a database using the user interface. To connect directly from the command line, type psql in the Terminal. This allows users to connect to a database simply by clicking on it, or to initiate or alter databases in the command line as needed. There are also other options if you wish to use a graphical client, detailed here. If you are comfortable using the command line, use of Postgres.app or any graphical client is not essential. Set-up via the command line is covered below.