Installing PostgreSQL on a Mac with Homebrew

I'm a full-stack developer from South Africa πΏπ¦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa πΏπ¦. I love writing about JavaScript, HTML and CSS.
Thanks Avinash! Glad you think so π
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

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 been loving Postgres myself, 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.

In this article, I'll be using Homebrew. If you haven't used it before, check out my article on using Homebrew.
The first thing we want to do is install Postgres.
Before running any install command in Homebrew, it's good to make sure 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!
To start the database, you can simply 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.

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 here is chris, and my password is super secure as it is: password.
Note: Use secure passwords, please this is just a demo setup.
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".

As for the connection details, you should use:
chris.password.postgres.The rest of the data should already be set up correctly.
You can then test the connection by clicking the "Test" button at the bottom. It should turn everything green.

And that's it you are now connected to your Postgres database.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter