correct way to start/stop postgres database pg_ctl or service postgres

Viewed 32111

I would like to know correct way of starting/stopping postgres database. There are two ways

  1. pg_ctl start/stop
  2. service postgresql start/stop

I would like to know how they are different from each other, which one should I use? are their any pros/cons.

I check online but didnt get satisfactory answer.

Thanks in advance

3 Answers

If you are using Mac with brew

To start:

brew services start postgresql

To stop:

brew services stop postgresql

Using pg_ctl

To start:

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

To stop:

pg_ctl stop -D /usr/local/var/postgres -m smart

See: https://www.postgresql.org/docs/current/app-pg-ctl.html

cd /datadir

pg_ctl -D $(pwd) stop

pg_ctl -D $(pwd) start

#pg_ctl needs the path of the data (-D) 

Can be directly used:

pg_ctl -D /mnt/raid/pdb stop

pg_ctl -D /mnt/raid/pdb stop

Ref

Related