How to start and stop Postgres properly

tan21098
Oct 23, 2020

If you do not have a user account, create one:

$ createuser -s postgres

Start:

$ postgres -D /usr/local/var/postgres

or

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

Stop:

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log stop

If you force stop the terminal or used ctrl+c to stop the process:

$ cat /usr/local/var/postgres/postmaster.pid
$ kill -3 PID # PID is the first line you get after running cat

If you are using homebrew:

$ brew services start postgresql$ brew services stop postgresql

--

--