天天看點

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