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 //重載防火牆
參考資料:官方網址