48

In Linux, it can be done by /etc/init.d/postgresql-9.2 restart. My OSX is not a server app.

I think it it can be done by ALTER USER postgres with password '1234'; postgreQSL prompt but I am not sure if it is the meant way.

How can you restart the PostgreSQL server in OSX?

3 Answers3

119

Brew has that covered:

brew services restart postgresql
33

Manually Start PostgreSQL:

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

Manually Stop PostgreSQL:

pg_ctl -D /usr/local/var/postgres stop -s -m fast

This stackoverflow discussion really goes into some great detail, with many more options. I used it to create an alias to just run:

postgresql.server stop
postgresql.server start
tron_jones
  • 3,830
  • 2
  • 19
  • 23
  • This alias does the trick: alias postgresql.server='function pgsql_server() { case $1 in "start") echo "Trying to start PostgreSQL..."; pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start ;; "stop") echo "Trying to stop PostgreSQL..."; pg_ctl -D /usr/local/var/postgres stop -s -m fast ;; esac }; pgsql_server' Commands: *postgresql.server start* or *postgresql.server stop* – Igor de Lorenzi Apr 13 '16 at 16:44
2

I'm on a brew install postgresql@9.6 for legacy reasons, and actually needed to:

# First, close all connections, e.g. application servers and psql connections, then
brew services stop postgres
killall postgres
brew services start postgres
pzrq
  • 121