将postgresql配置为Linux服务管理 systemctl service

       发行版安装的数据库在装完后会自动添加数据库服务,但编译安装的不会,需要手动添加。

cd postgresql-14.0/contrib/start-scripts/
cp linux /etc/init.d/postgresql
cd /etc/init.d/

vi postgresql

修改以下部分

## EDIT FROM HERE

# Installation prefix
prefix="/data/postgres/base/14.0"

# Data directory
PGDATA="/data/postgres/pg5432/data"

# Who to run the postmaster as, usually "postgres".  (NOT "root")
PGUSER=postgres

# Where to keep a log file
PGLOG="$PGDATA/log"

再改下启动命令

case $1 in
  start)
        echo -n "Starting PostgreSQL: "
        test -e "$PG_OOM_ADJUST_FILE" && echo "$PG_MASTER_OOM_SCORE_ADJ" > "$PG_OOM_ADJUST_FILE"
        su - $PGUSER -c "$PGCTL start -D '$PGDATA' -s"
        echo "ok"
        ;;

加执行权限   chmod +x postgresql

通过下面的命令添加到服务中 

chkconfig --add postgresql

否则会报错

[root@localhost init.d]# systemctl stop postgresql
Failed to stop postgresql.service: Unit postgresql.service not loaded.

相应的,可通过下述命令删除

chkconfig --del postgresql

如果后面修改了postgresql文件,需要reload

systemctl daemon-reload

启动测试

systemctl start postgresql 
systemctl status postgresql   
ps -ef|grep postgres

关闭测试

systemctl stop postgresql
ps -ef|grep postgres

参考

PGCE课程《服务管理》 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hehuyi_In

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值