系统环境:Centos 7.5
1.sudo vim /etc/rc.d/rc.local
2.在最后两行添加如下内容:
source /etc/profile
su postgres -c "/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data"

3.按“:wq”保存!
4.终端输入:
chmod +x /etc/rc.d/rc.local