当前位置: 移动技术网 > 网络运营>服务器>Linux > Ubuntu 16.04设置PostgreSQL开机启动的方法

Ubuntu 16.04设置PostgreSQL开机启动的方法

2019年05月29日  | 移动技术网网络运营  | 我要评论

由于postgresql是编译安装的,需要设置开机启动。对于ubuntu系统来说,和red hat之类的系统稍微有一点不一样。

首先第一步,由于我们习惯于使用red hat这样的系统,所以我们需要弄一个chkconfig出来。这个命令是配置red hat服务启动停止的命令,但是在ubuntu上没有。我们可以使用sysv-rc-conf。

sudo apt install sysv-rc-conf

安装完成sysv-rc-conf之后,我们把他换成chkconfig。毕竟这个命令太难记住了。

sudo cp /usr/sbin/sysv-rc-conf /usr/sbin/chkconfig

接下来我们可以尝试使用chkconfig命令来查看

这个弄好之后,我们需要到postgresql的安装压缩包的/postgresql-10.3/contrib/start-scripts目录下。目录下面有好几个系统的配置文件,我们这里使用的是ununtu就选择linux,把这个文件复制到/etc/init.d/下面。并赋予可执行x权限。

postgres@postgres-n65s01:~/postgresql-10.3/contrib/start-scripts$ ls
freebsd linux macos osx
postgres@postgres-n65s01:~/sudo cp linux /etc/init.d/
postgres@postgres-n65s01:/etc/init.d$sudo mv linux postgresql-10.0
postgres@postgres-n65s01:/etc/init.d$chmod a+x postgresql-10.0

做完上述操作之后需要修改该文件,主要修改下列两个位置

prefix是postgresql安装目录,pgdata是数据库文件所在目录。修改完成之后保存。执行下列命令,把服务设置成自动启动即可。

postgres@postgres-n65s01:/etc/init.d$ sudo chkconfig postgresql-10.0 on
postgres@postgres-n65s01:/etc/init.d$ sudo chkconfig --list | grep postgres
postgresql-1 2:on 3:on 4:on 5:on

再一次重启主机之后,可以发现postgresql数据库可以自动启动了。

postgres@postgres-n65s01:/etc/init.d$ ps -ef | grep pgdata
postgres 2460   1 0 19:19 ?    00:00:00 /opt/postgresql-10/bin/postmaster -d /pgdata/data
postgres 4683 2853 0 19:43 pts/18  00:00:00 grep --color=auto pgdata

总结

以上所述是小编给大家介绍的ubuntu 16.04设置postgresql开机启动的方法,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网