1 進(jìn)入postresql官網(wǎng)下載頁面,提示了centos相關(guān)下載安裝等信息。
https://www.postgresql.org/download/linux/redhat/

2 連接到centos7服務(wù)器

3 根據(jù)官網(wǎng)提示在命令行中下載安裝
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

yum install postgresql11
yum install postgresql11-server
附帶安裝
yum install postgresql11-libs
yum install postgresql11-contrib
yum install postgresql11-devel
4 數(shù)據(jù)庫初始化與設(shè)置自啟動
/usr/pgsql-11/bin/postgresql-11-setup initdb
systemctl enable postgresql-11
systemctl start postgresql-11

這一步初始化數(shù)據(jù)庫命令會在 /var/lib/pgsql 目錄下創(chuàng)建名稱為11文件夾,11為數(shù)據(jù)庫版本,如果安裝的是其他版本,對應(yīng)的是其版本號(9.4、9.5);這里如果已經(jīng)有對應(yīng)版本的文件夾了,初始化這一步會報(bào)錯,需要你自行去刪除對應(yīng)的文件夾,再去初始化。
5 默認(rèn)會創(chuàng)建一個名為postgres的linux登錄用戶,這里進(jìn)行密碼修改
(注意,這里修改的是linux登陸的賬號密碼,不是數(shù)據(jù)庫的)
passwd postgres

6 編輯一些遠(yuǎn)程連接信息,讓所有計(jì)算機(jī)能訪問到該測試數(shù)據(jù)庫
6.1 對postgresql.conf文件進(jìn)行編輯
cd var/lib/pgsql/11/data
vim postgresql.conf
修改前:

輸入a進(jìn)入插入編輯模式,對該文件進(jìn)行編輯;
去掉#,修改localhost為*
修改后如下,按下esc退出插入編輯模式,并輸入:wq保存退出

6.2同樣目錄下,對pg_hba.conf文件進(jìn)行編輯
vim pg_hba.conf
修改前:

輸入a進(jìn)入插入編輯模式,對該文件進(jìn)行編輯
修改后如下,按下esc退出插入編輯模式,并輸入:wq保存退出

7 重新啟動服務(wù)
systemctl restart postgresql-11
8 用postgres賬號登錄centos服務(wù)器,并修改數(shù)據(jù)庫用戶密碼(或者直接 su postgres 切換過去)
ssh postgres@ip -p 端口
psql -U postgres
\password

查看版本

9 在數(shù)據(jù)庫客戶端測試登錄

10 備用卸載
yum remove postgresql*

前人經(jīng)驗(yàn)參考
http://www.itdecent.cn/p/3f8d77d258d8
http://www.itdecent.cn/p/639ebb43bfb4
https://www.cnblogs.com/freeweb/p/8006639.html
http://www.postgresonline.com/article_pfriendly/362.html
https://www.cnblogs.com/yanmiao/p/3262306.html