通過官網獲取下載地址,選擇自己所需要的版本:
https://www.postgresql.org/download/

開始安裝:
1.安裝存儲庫
yum install
https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2.安裝客戶端
yum install postgresql96
3.安裝服務端
yum install postgresql96-server
4.驗證是否安裝成功
rpm -aq| grep postgres

5.初始化數據庫
/usr/pgsql-9.6/bin/postgresql96-setup initdb
6.啟用開機自啟動
systemctl enable postgresql-9.6
systemctl start postgresql-9.6
7.配置防火牆(阿里雲ECS不需要執行此項)
firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload

8.修改用戶密碼
su - postgres 切換用戶,執行后提示符會變為 '-bash-4.2$' psql -U postgres 登錄數據庫,執行后提示符變為 'postgres=#' ALTER USER postgres WITH PASSWORD 'postgres' 設置postgres用戶密碼為postgres \q 退出數據庫
9.開啟遠程訪問
vi /var/lib/pgsql/9.6/data/postgresql.conf 修改#listen_addresses = 'localhost' 為 listen_addresses='*'
10.信任遠程連接
vi /var/lib/pgsql/9.6/data/pg_hba.conf 修改如下內容,信任指定服務器連接 # IPv4 local connections: host all all 127.0.0.1/32 trust host all all (你的服務器IP)/32(需要連接PGSQL的服務器IP) trust
11.重啟服務
systemctl restart postgresql-9.6
12.阿里雲ECS配置允許外網訪問PGSQL
