1.安装rpm包
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2.安装对应package
yum install postgresql95
yum install postgresql95-server
3.设置服务自启动
/usr/pgsql-9.5/bin/postgresql95-setup initdb
systemctl enable postgresql-9.5
4.启动服务
systemctl start postgresql-9.5
5.设置数据库用户名
su - postgres //切换用户,执行后提示符会变为 '-bash-4.2$'
psql -U postgres //登录数据库,执行后提示符变为 'postgres=#'
ALTER USER postgres WITH PASSWORD '你设置的密码' //设置postgres用户密码
\q //退出数据库
6.开启远程访问
vi /var/lib/pgsql/9.5/data/postgresql.conf
修改#listen_addresses = ‘localhost’ 为 listen_addresses=’*’
7.关闭防火墙
firewall-cmd --add-service=postgresql --permanent //开放postgresql服务
firewall-cmd --reload //重载防火墙
参考资料:官方网址