CentOS7 yum安裝、配置PostgreSQL 9.6


PostgreSQL 9.6安裝

1、添加RPM

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2、安裝PostgreSQL 9.6

sudo yum install -y postgresql96-server

3、初始化數據庫

sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb

4、設置開機自啟動

sudo systemctl enable postgresql-9.6

5、啟動服務

sudo systemctl start postgresql-9.6

6、查看版本

psql --version

 

PostgreSQL 9.6配置

1、修改用戶密碼

su - postgres
psql -U postgres
ALTER USER postgres WITH PASSWORD '123456' 
\q

2、開啟遠程訪問

vi /var/lib/pgsql/9.6/data/postgresql.conf
修改#listen_addresses = 'localhost'  為  listen_addresses='*'

3、信任遠程連接

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      192.168.137.1/32(需要連接的服務器IP)  trust

#“host” 代表主機類型,第一個“all”代表db ,第二個“all”代表user ,“192.168.137.1/32” 代表client ip,“trust”代表認證方式;
#認證方式除“trust”外,還有“peer”, “ident”等,具體可參考pg-hba文件: https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html

4、重啟服務

systemctl restart postgresql-9.6.service

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM