1.如果有用yum安裝過舊版,卸載掉:
yum remove postgresql*
2.更新一下yum:
sudo yum update
3.去 官網 找到 適合你系統 的資源的下載地址,然后使用wget命令下載:
wget http://yum.pgrpms.org/9.2/redhat/rhel-5-x86_64/pgdg-centos92-9.2-6.noarch.rpm
4.然后執行:
sudo rpm -ivh pgdg-centos92-9.2-6.noarch.rpm
5.使用yum安裝(96和9.6也就是當前安裝的pg的版本號):
sudo yum -y install postgresql96-server
6.初始化數據庫:
sudo service postgresql-9.6 initdb
7.如果提示-bash: service: command not found,則需要設置環境變量:
vi .bash_profile
在PATH這行已有的內容后面增加/sbin:
export PATH=$PATH:/sbin:
8.啟動postgreSQL:
sudo service postgresql-9.6 start
9.設置開機自動啟動服務:
sudo chkconfig postgresql-9.6 on
10.啟動postgreSQL:
psql
11.可能遇到的錯誤:
FATAL: role "user" does not exist
你可以使用超級用戶來使用pg:
sudo su postgres
或者 執行以下命令來為普通用戶創建pg用戶信息:
sudo su - postgres
createuser 你的用戶名
createdb -O 你的用戶名 你的用戶名
FATAL: Peer authentication failed for user "postgres"
找到 pg_hba.conf 文件(可能在/var/lib/psql/9.6/data的子目錄文件夾內,建議全局搜索),修改:
local all postgres peer
改為:
local all postgres md5
再次登錄,應該會需要你輸入密碼,所以需要為pg用戶設置密碼: 參考資料
再次執行以下命令,應該就可以開始正常使用了:
psql
參考鏈接:
http://www.zuimoban.com/jiaocheng/postgresql/3771.html
http://www.jb51.net/os/RedHat/277412.html
http://stackoverflow.com/a/28214126/5542006
