root用户
cd /usr/lib/systemd/system
vi postgresql.service #增加下面内容,并根据实际内容修改
[Unit]
Description=PostgreSQL database server
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0
Environment=PGSTARTTIMEOUT=300
Environment=PGDATA=/opt/pg12.4/data
ExecStart=/opt/pg12.4/bin/pg_ctl start -D ${PGDATA} -l /home/postgres/logfile -s -w -t ${PGSTARTTIMEOUT}
ExecStop=/opt/pg12.4/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/opt/pg12.4/bin/pg_ctl reload -D ${PGDATA} -s
[Install]
WantedBy=multi-user.target
在建立文件后,postgresql.serivce需要将文件加载进systemctl并且在打开enable
systemctl daemon-reload
systemctl enable postgresql
systemctl start postgresql
systemctl list-units --type=service --state=active
systemctl list-units --type=service --state=running