postgresql 启动关闭脚本

如果是 yum/apt-get 安装,就用 service 启动和关闭
如果时 make 安装,就需要写个启动关闭脚本

$ vi  pgsql9.1_start.sh
pg_ctl start -D /var/lib/postgresql/9.1/main -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"

$ vi pgsql9.1_stop.sh
pg_ctl stop -m fast -D /var/lib/postgresql/9.1/main

或者在非postgres 用户的脚本里执行

su - postgres -c "/usr/lib/postgresql/9.1/bin/pg_ctl start -D /var/lib/postgresql/9.1/main/ -o '-c config_file=/etc/postgresql/9.1/main/postgresql.conf'"
sleep 120

su - postgres -c "/usr/lib/postgresql/9.1/bin/pg_ctl stop -m fast  -D /var/lib/postgresql/9.1/main/"
sleep 120

为什么要 sleep 120 ,有兴趣的哥们可以做个实验。

原文地址:https://www.cnblogs.com/ctypyb2002/p/9793113.html