Installing PostgreSQL on a Mac with Homebrew


How to install a PostgreSQL database on Mac using Homebrew

12 Jan, 2022 Β· 3 min read

Suppose you had a look at the 2021 stack overflow developer survey results. In that case, you might have seen that PostgreSQL, or Postgres for short, is now the second most loved database.

And I've loved Postgres, so time to dedicate an article on how to set it up on a Mac. This article will guide you through installing Postgres on your Mac and exploring the first database.

Stack overflow most loved databases 2021

In this article, I'll be using Homebrew. If you haven't used it before, check out my article on using Homebrew.

Installing Postgresql with Homebrew

The first thing we want to do is install Postgres.

Before running any install command in Homebrew, it's good to ensure you are up to date.

brew update

Now it's time to install Postgres, and you can run this command.

brew install postgresql

Once it's done, you should see this output line amongst some other stuff.

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

That means you are set!

Managing the Postgres database

To start the database, you can run the following command in your terminal:

brew services start postgresql

And to stop the Postgres database from running:

brew services stop postgresql

Once it's 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.


My user's name here is chris, and my password is super secure as it is: password.

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

Connecting to the Postgres database

I find it easiest to use visual database connection tools.

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

We'll use TablePlus to connect to our newly created Postgres database.

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!

Thank you for reading my blog. 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

Submit button outside the form

4 Dec, 2022 Β· 1 min read

Submit button outside the form

Join 1900 devs and subscribe to my newsletter