Postgresql数据库设置开机自启动

1、查找Postgresql数据库开机自启动脚本位置

[root@dragon ~]# find / -name start-scripts
/opt/postgres/postgresql-9.4.12/contrib/start-scripts

[root@dragon ~]# cd /opt/postgres/postgresql-9.4.12/contrib/start-scripts
[root@dragon start-scripts]# ll
总用量 8
-rw-r--r-- 1 1107 1107 1529 5月   9 2017 freebsd
-rw-r--r-- 1 1107 1107 3437 5月   9 2017 linux
drwxrwxrwx 2 1107 1107   87 5月   9 2017 osx

# linux文件为启动脚本文件

2、将linux文件复制到 /etc/init.d 目录下,并且将其重名为postgresql

[root@dragon start-scripts]# cp linux /etc/init.d/postgresql

3、进入 /etc/init.d 目录下,修改postgresql文件

[root@dragon start-scripts]# cd /etc/init.d/
[root@dragon init.d]# ls
functions  grafana-server  jexec  netconsole  network  postgresql  README
[root@dragon init.d]# vim postgresql 

将prefix设置为postgresql的安装路径:/usr/local/postgresql
将PGDATA设置为postgresql的数据目录路径:/usr/local/postgresql/data

4、添加到开机启动

[root@dragon init.d]# chomd +x postgresql 
[root@dragon init.d]# chkconfig --add postgresql

[root@dragon init.d]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

jexec          0:关1:开2:开3:开4:开5:开6:关
netconsole     0:关1:关2:关3:关4:关5:关6:关
network        0:关1:关2:开3:开4:开5:开6:关
postgresql     0:关1:关2:开3:开4:开5:开6:关

 5、重启服务器测试

[root@dragon init.d]# reboot

[root@dragon init.d]# systemctl status postgresql
● postgresql.service - SYSV: PostgreSQL RDBMS
   Loaded: loaded (/etc/rc.d/init.d/postgresql; bad; vendor preset: disabled)
   Active: active (exited) since 一 2022-10-10 10:53:31 CST; 44min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 941 ExecStart=/etc/rc.d/init.d/postgresql start (code=exited, status=0/SUCCESS)

10月 10 10:53:31 dragon systemd[1]: Starting SYSV: PostgreSQL RDBMS...
10月 10 10:53:31 dragon su[943]: (to postgres) root on none
10月 10 10:53:31 dragon systemd[1]: Started SYSV: PostgreSQL RDBMS.
10月 10 10:53:31 dragon postgresql[941]: Starting PostgreSQL: ok

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值