postgresql数据库简单设置开机启动

2025-10-21 07:37:44

1、进入postgresql源码搁泪良安装包主目录

执行 :

find ./* -name linux

会出现:

./contrib/start-scripts/linux 

上所示文件为pgsql自带的脚本(位于源码安装包中),例如:

          postgresql-10.10.tar.gz

2、 将上述找到的文件拷贝到linux系统的    /etc/init.d/ 醒光  目录中

在pgsql主目录执行:

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

3、对上述文件赋予执行权限,并添加到开机启动

进入/etc/init.d/目录:

cd /etc/init.d/

赋予权限:

chomd +x  postgresql

添加到开机自启动

chkconfig  postgresql   on

查看是否添加成功:

chkconfig  --list | grep  postgresql

(2,3,4,5都是打蚊缝开了(on),0,1,6 是关(off))

关闭开机自启动:

chkconfig   postgresql  off

4、若以上步骤过于繁琐,可使用以下脚本进行自动配置

该脚本文件需要放置于postgresql安装包根目录,例如:

/opt/postgresql-10.10/(安装包主目录)

#!/bin/bash

PGSQL_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

5、以上步骤仅限于将数据库安装在默认路径的,若安装在其他目录,需要修改自启动脚本中相关文件的路径

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢