Linux下PostgreSQL开机启动配置方法

操作系统:Centos

目前官方文档提到有两种方式开启PostgreSQL开机启动方法

方式一、使用源码提供的脚本

1、Linux脚本路径为源码包解压后contrib/start-scripts/linux ;

2、将linux文件复制到/etc/init.d或者/etc/rc.d

$ cp contrib/start-scripts/linux /etc/init.d/pgsql

3、根据安装路径修改pgsql文件中的配置项

修改prefixPGDATA配置项

## EDIT FROM HERE

# Installation prefix (安装路径)
prefix=/usr/local/pgsql

# Data directory (data路径)
PGDATA="/usr/local/pgsql/data"

4、修改pgsql文件权限

$ chmod +x pgsql

5、开机执行pgsql文件

$ chkconfig --add pgsql

方式二、将启动命令加入到初始化脚本中

将su postgres -c 'pg_ctl start -D /usr/local/pg:sql/data -l serverlog' 添加到/etc/rc.local中

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
su postgres -c 'pg_ctl start -D /usr/local/pg:sql/data -l serverlog'

参考资料:https://www.postgresql.org/docs/10/static/server-start.html

猜你喜欢

转载自blog.csdn.net/ifucking/article/details/79892580