Subscribe

Install PostgreSQL on Mac with Homebrew

✍️

Quick start Postgres DB on Mac with Homebrew: Install & launch brew PostgreSQL effortlessly.

2 Feb, 2024 · 3 min read

Suppose you had a look at the 2021 stack overflow developer survey results.

In that case, you may see that PostgreSQL, or Postgres for short, is now the second most loved database. Stack overflow most loved databases 2021

I personally love Postgres as well. Hence, time to dedicate an article on how to set up PostgreSQL on a Mac.

In this tutorial you will learn to install Postgres on a Macintosh using Homebrew, plus we will explore the database a bit 👀.

If you haven’t used Homebrew before, check out my article on using Homebrew.

How to install Postgres with Homebrew

The first thing we want to do is to install Postgres DB.

Before running any install command in Homebrew, it’s good to ensure your installation is up to date.

brew update

Now is the time; to install PostgreSQL run this command:

brew install postgresql

Once the installation is finished, you should see this output line amongst some other information:

This formula has created a default database cluster with:
  initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres

That means the Postgres DB is installed and you are set!

Start & Manage a Postgres database

To start the database, run the following command in the terminal:

brew services start postgresql

And to stop the Postgres database from running:

brew services stop postgresql

Once the DB is up and running, we want to create a root user to log in and interact with the database.

psql postgres

This will log you into the Postgres server.

Postgres server login

From here, you can create a new user with a password.

CREATE ROLE chris WITH LOGIN PASSWORD 'password';
ALTER ROLE chris CREATEDB;

My user’s name is chris, and my password is super secure as: password.

Note: Use secure passwords, please. This is just a demo setup.

Connect to PostgreSQL DB

The easiest way to connect to Postgres is via the visual database connection tools.

If you are unsure what client to use: I’ve written down my top 5 SQL database clients.

We’ll use TablePlus to connect to our newly created PostgreSQL DB.

  • Open the app, and create a “new connection”.
  • For the type, you can choose “PostgreSQL”.
TablePlus new PostgreSQL database connection

As for the connection details, you should use:

  • User: The one you just created, in my case chris.
  • Password: The password you set, in my case, password.
  • Database: This will be postgres.

The rest of the data should already be set up correctly.

You can test the connection by clicking the “Test” button at the bottom. It should turn everything green.

Postgres connection green

And that’s it. You are now connected to your Postgres database 🚀

Thank you for reading, and let’s connect!

Feel free to subscribe to my email newsletter and connect on Facebook or Twitter

Spread the knowledge with fellow developers on Twitter
Tweet this tip
Powered by Webmentions - Learn more

Read next 📖

Setting up a free PostgreSQL database on Heroku

22 Oct, 2021 · 2 min read

Setting up a free PostgreSQL database on Heroku

I wrote 1000 articles, what’s next?

22 Dec, 2022 · 3 min read

I wrote 1000 articles, what’s next?

Join 2097 devs and subscribe to my newsletter