Rocky9下给PostgreSQL 15.2添加服务文件,以服务方式启动
该方法用于编译方式安装的PostgreSQL,yum安装的自带服务,实现步骤如下:
1、创建服务文件:
vi /usr/lib/systemd/system/postgresql.service
[Unit]
Description=PostgreSQL database server
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
# Port number for server to listen on
Environment=PGPORT=5432
# Location of database directory
Environment=PGDATA=/data/pgsql
# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog
# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
#ExecStartPre=/usr/local/pgsql/bin/postgresql-check-db-dir ${PGDATA}
ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300
[Install]
WantedBy=multi-user.target
2、设置文件权限、加入开机启动:
sudo chmod 754 /usr/lib/systemd/system/postgresql.service
sudo systemctl enable postgresql
[sudo] password for postgres:
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.
sudo systemctl reload postgresql #重启服务
sudo systemctl stop postgresql #停止服务
Tag标签:「PostgreSQL 服务 service」更新时间:「2023-03-04 22:35:03」阅读次数:「971」