1. pgsql_home/contrib/start-scripts/linux
2. 源码编译安装包
进入postgresql源码安装包主目录执行 :find ./* -name linux会出现:./contrib/start-scripts/linux 上所示文件为pgsql自带的脚本(位于源码安装包中),例如: postgresql-10.10.tar.gz
将上述找到的文件拷贝到linux系统的 /etc/init.d/ 目录中在pgsql主目录执行:cp ./contrib/start-scripts/linux /etc/init.d/postgresql
若以上步骤过于繁琐,可使用以下脚本进行自动配置该脚本文件需要放置于postgresql安装包根目录,例如:/opt/postgresql-10.10/(安装包主目录) #!/bin/bashPGSQL_HOME=$(cd `dirname $0`; pwd)for path in $(/usr/bin/find ./* -name linux) do if [ `ls $path | grep 'contrib'` ];then echo '检测到文件: ''$path' echo '开始配置........' cp $PGSQL_HOME/$path /etc/init.d/postgresql chmod +x /etc/init.d/postgresql cd /etc/init.d/ chkconfig postgresql on echo '配置结果' echo `chkconfig --list|grep postgresql` exit 0; fi done
以上步骤仅限于将数据库安装在默认路径的,若安装在其他目录,需要修改自启动脚本中相关文件的路径
需要有postgresql数据库的安装包中存在相关文件