Postgres on Mac with Brew 💻

Brewing PostgreSQL on OS X

✋ This article is intended to save time while setting up the environment using Brew.

  • Install Brew:
$ /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Update brew
$ brew update
  • List Running Services
$ brew services list
mongodb-community stopped
postgresql stopped
  • Uninstall Existing Postgres (Only if you want) Remove the existing one if needed and not working.
$ brew uninstall --force postgresql
  • Remove the files on disk. Leftover manual remove
$ rm -rf /usr/local/var/postgres
  • Now, Install Postgres
$ brew install postgres
  • Time to start the Postgres running in the background.
$ brew services start postgresql

→ An alternative way to start:

$ pg_ctl -D /usr/local/var/postgres start
  • Create DB
$ initdb /usr/local/var/postgres

→ Delete a DB?

$ rm -r /usr/local/var/postgres
  • Create a User
$ /usr/local/Cellar/postgresql/X.X.X/bin/createuser -s postgres
  • Get the CLI
$ brew install postgis
  • Get inside:
$ psql DBNAME USERNAMEExample: pssql postgres gopi
  • Change the DB Password:
$ ALTER USER postgres WITH PASSWORD ‘postgres’;
  • Create DB, Role, Password at one shot:
$ createdb -h localhost -p 5432 -U postgres springbootdb password testme

Clients:

Download and install

pgadmin4 or DBeaver

PgAdmin can be opened at:

$ http://127.0.0.1:59163/browser/

Find the publication here: https://medium.com/thinkspecial

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store