Centos7设置postgresql数据库开机自启动方式
前言
PostgreSQL的开机自启动脚本位于PostgreSQL源码目录的contrib/start-scripts路径下
如果不知道具体的路径,可以用find命令进行查找。
命令如下:
[root@admin ~]# find / -name start-scripts /root/postgresql-14.4/contrib/start-scripts
linux文件即为linux系统上的启动脚本

操作步骤
1、将Linux文件复制到 /etc/init.d 目录下,并且将其重名为postgresql
[root@admin start-scripts]# cp linux /etc/init.d/postgresql
2、进入 /etc/init.d 目录下,修改postgresql文件
[root@admin start-scripts]# cd /etc/init.d/ [root@admin init.d]# vim postgresql
查看postgresql用户下的环境变量,然后做以下修改:
将prefix设置为postgresql的安装路径:/usr/local/postgresql
将PGDATA设置为postgresql的数据目录路径:/usr/local/postgresql/data

保存退出!
3、添加到开机启动
修改文件属性并添加开机启动
[root@admin init.d]# chmod a+x postgresql
[root@admin init.d]# chkconfig --add postgresql
[root@admin init.d]# ll
total 44
-rw-r--r--. 1 root root 18281 Aug 24 2018 functions
-rwxr-xr-x. 1 root root 4569 Aug 24 2018 netconsole
-rwxr-xr-x. 1 root root 7923 Aug 24 2018 network
-rwxr-xr-x 1 root root 3569 Aug 26 09:54 postgresql
-rw-r--r--. 1 root root 1160 Oct 31 2018 README
[root@admin init.d]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off服务正常开启,重启机器测试:
重启之后,开机,服务正常开启:

总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
CentOS 6.4系统下编译安装LNMP和配置PHP环境具体步骤
下面介绍的是CentOS 6.4系统下编译安装LNMP和配置PHP环境具体步骤,感兴趣的朋友可以参考下,希望对你配置php环境有所帮助2013-05-05
CentOS 安装软件出现错误:/lib/ld-linux.so.2: bad ELF interpreter 解决
这篇文章主要介绍了CentOS 安装软件出现错误:/lib/ld-linux.so.2: bad ELF interpreter 解决的相关资料,需要的朋友可以参考下2017-03-03
Ubuntu14.04服务器环境下配置PHP7.0+Apache2+Mysql5.7的方法
这篇文章主要介绍了Ubuntu14.04服务器环境下配置PHP7.0+Apache2+Mysql5.7的方法,较为详细的分析了Ubuntu14.04操作系统环境下配置PHP7.0+Apache2+Mysql5.7的具体步骤与相关命令使用技巧,需要的朋友可以参考下2018-04-04
Windows 10 太难用如何定制你的 Ubuntu方法详解
这篇文章主要介绍了Windows 10 太难用,如何定制你的 Ubuntu,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-08-08
详解linux下redis安装、启动与停止,redis做成服务
这篇文章主要介绍了详解linux下redis安装、启动与停止,redis做成服务,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。2016-12-12


最新评论