天天看点

PostgreSQL自启动设置

当数据库服务器重启时,默认的数据库实例是不会自己启动的,需要人为操作,手工把数据库启动,

但如果想数据库服务器在启动的同时,数据库实例也启动,需要将数据库实例添加到自启动里

有两种实现方法:

1 直接修改/etc/c.local文件

vi /etc/rc.local
添加
sudo -u postgres -i /opt/pg10/bin/pg_ctl -D /export/pg10beta_data start -l /home/postgres/start.log           

2 在/etc/init.d下添加postgresql 文件

1 找到postgresql安装包
2 cp 安装包路径/contrib/start-scripts/linux /etc/init.d/postgresql
3 给postgresql文件赋权: chmod +x postgresql
4 编辑postgresql 文件
vi postgresql
prefix=/opt/pgsql  --postgresql 安装路径
PGDATA=/home/postgres/data  --postgresql的数据目录

5 查看数据库实例状态
# service postgresql status
pg_ctl: no server running
# service postgresql start
Starting PostgreSQL:ok

6 添加到开机自启动:
# chkconfig --add postgresql