PostgreSQL on macOS
I needed to install PostgreSQL locally on my macOS as I started a new hobby project where I'm planning to use it.
I'm using homebrew to install it as it is an easy way to add it and later to remove it.
Run this in your terminal
brew install postgres
Starting PostgreSQL manually
I liked to have total control when the PostgreSQL is running so I will start it like this:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
In addition to just starting it will create a log for PostgreSQL loggings.
To automatically start it
When you installed PostgreSQL with homebrew you might have noticed that it have you the following information in the terminal:
To have launchd start postgresql now and restart at login: brew services start postgresql
Stopping PostgreSQL manually
To stop it, just run this command:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
I created few aliases for convenience. Start, stop and tailing the log.
alias pgstart='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start' alias pgstop='pg_ctl -D /usr/local/var/postgres stop -s -m fast' alias pglog='tail -f /usr/local/var/postgres/server.log'
I am using Postico to connect to my development database (well, currently it does no have anything else than development :D). It is available for macOS for free, but some features are limited.