Installing Postgres with brew in 2 easy steps

By | August 29, 2021

I made a mistake by downloading PostgresSQL from the official website, something I used to do in my Windows days. It worked fine but I couldn’t figure out how to manually start and stop Postgres or figure out how to run it as a service or make it not run as a service.

Using brew is much easier because it is literally 2 steps:

brew install postgresql

and

brew services start postgresql

To start postgresql manually, use:

pg_ctl -D /usr/local/var/postgres start

Then to stop it, you run:

brew services stop postgresql

and to see the services and their status, run:

brew services

pgAdmin4

I did download pgAdmin4 though as a GUI to help access the db. If you encounter the error:

FATAL: role “postgres” does not exist on OSX then you’ll want to run:

/usr/local/opt/postgres/bin/createuser -s postgres

This creates a user called postgres.

Update:

/usr/local/opt/postgres\@14/bin/createuser -s postgres

Some useful commands

psql -U postgres (to log in)

psql --version
psql --help

psql --list

Category: OSX

Leave a Reply

Your email address will not be published. Required fields are marked *