0
点赞
收藏
分享

微信扫一扫

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


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

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

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

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"

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

再改下启动命令

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

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

关闭测试

systemctl stop postgresql
ps -ef|grep postgres

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

参考

PGCE课程《服务管理》 

举报

相关推荐

0 条评论