63

Ubuntu 16.04设置PostgreSQL开机启动

 5 years ago
source link: http://www.dboracle.com/archivers/ubuntu-16-04设置postgresql开机启动.html?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

由于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命令来查看

NraQnub.png!web

这个弄好之后,我们需要到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

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

zIVzmym.png!web

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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK