SaltyCrane Blog — Notes on JavaScript and web development

postgres on Mac OS (homebrew) notes

Here are my notes on running postgresql on macOS Mojave installed with Homebrew. I also wrote some notes on running postgres in Docker here.

install postgres

$ brew install postgresql

start postgres

$ brew services start postgresql

restart postgres

$ brew services restart postgresql

postgres version

$ postgres --version
postgres (PostgreSQL) 11.1

check postgres is running (option 1)

$ brew services list
Name       Status  User      Plist
postgresql started eliot /Users/eliot/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

check postgres is running (option 2)

$ ps -ef | grep postgres
  502   629     1   0 10Jan19 ??         0:12.39 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres
  502   715   629   0 10Jan19 ??         0:00.29 postgres: checkpointer
  502   716   629   0 10Jan19 ??         0:02.39 postgres: background writer
  502   717   629   0 10Jan19 ??         0:02.32 postgres: walwriter
  502   718   629   0 10Jan19 ??         0:09.99 postgres: autovacuum launcher
  502   719   629   0 10Jan19 ??         0:45.17 postgres: stats collector
  502   720   629   0 10Jan19 ??         0:00.22 postgres: logical replication launcher
  502 73227 19287   0  8:43PM ttys003    0:00.00 grep postgres

postgres log file

/usr/local/var/log/postgres.log

postgres data directory

/usr/local/var/postgres

psql commands

Start psql:
$ psql postgres
Help with psql commands:
postgres=# \?
List databases:
postgres=# \l
Connect to a database:
postgres=# \c mydatabase
List tables:
mydatabase=# \d