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

梦想与她 提交于 2021-01-22 00:21:38

问题


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


回答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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!