正确的方法来启动/停止postgres数据库pg_ctl或服务postgres

Nom*_*mad 4 postgresql

我想知道启动/停止postgres数据库的正确方法。有两种方法

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

我想知道它们之间的区别,我应该使用哪一个?是他们的优点/缺点。

我在网上检查,但没有得到满意的答复。

提前致谢

Vao*_*sun 5

如果您查看/etc/init.d/postgres${VER}文件,您会发现,当您运行service postgresql start/stop它时,会运行pg_ctl $OPTIONS start/stop. 唯一的区别是服务为您提供了存储环境变量和启用/禁用自动启动的便捷方式。

以上所有内容都可以手动完成,使用pg_ctl和一些脚本。


小智 5

如果您将Mac与brew一起使用

开始:

brew services start postgresql
Run Code Online (Sandbox Code Playgroud)

停止:

brew services stop postgresql
Run Code Online (Sandbox Code Playgroud)

使用pg_ctl

开始:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Run Code Online (Sandbox Code Playgroud)

停止:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log stop
Run Code Online (Sandbox Code Playgroud)