问题
I would like to know correct way of starting/stopping postgres database. There are two ways
pg_ctl start/stopservice 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
回答1:
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 -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
To stop:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log stop
回答2:
If you view /etc/init.d/postgres${VER} file, you will find out, that when you run service postgresql start/stop it runs pg_ctl $OPTIONS start/stop. The only difference is that service gives you handy way to store environmental variables and enable/disable autostart.
All above can be done manually, using pg_ctl and some scripting.
回答3:
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
来源:https://stackoverflow.com/questions/45671327/correct-way-to-start-stop-postgres-database-pg-ctl-or-service-postgres