postgresql的安裝
postgresql的linux在線安裝請參考:https://www.postgresql.org/download/linux/redhat/
postgresql離線的安裝:
- 下載安裝包,下載地址可以參考:https://yum.postgresql.org/rpmchart.php
- 安裝postgresql94-libs、postgresql94、postgresql94-server
- 安裝postgresql94-contrib時,有可能會報錯,需要先安裝依賴:libxslt-1.1.28-5.el7.x86_64。下載地址參考:https://centos.pkgs.org/7/centos-x86_64/libxslt-1.1.28-5.el7.x86_64.rpm.html這個是安裝9.4版本的依賴地址
postgresql的配置修改
修改監聽地址和端口
安裝好postgresql后,編輯配置文件/var/lib/pgsql/11/data/postgresql.conf,去掉listen_address='localhost'前的# port前的#或者是添加下面的代碼:
# *表示監聽所有的ip信息,也可以使用localhost、127.0.0.1等
listen_address = '*'
# 默認的監聽端口為5432,也可以換為其它的地址
port = 5432
修改鏈接數上限
max_connections = 1000
修改訪問控制
默認情況下,是不允許其它服務器訪問的,此時,需要添加ip訪問策略。ip的訪問控制在pg_hba.conf文件中(pg_hba.conf和postgresql.conf在同一目錄下)
#允許所有的服務器通過賬號密碼訪問
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
#指定ip訪問
host all all 34.56.34.64/32 md5
#ip段訪問
host all all 34.56.34.0/24 md5
postgresql相關常用命令
重啟postgres服務:systemctl restart postgresql-9.4
關閉psotgres服務:systemctl stop postgresql-9.4
重新加載配置文件:service postgresql-9.4 reload
注意
要在psotgresql中使用uuid等功能時,需要先安裝postgresql94-contrib 如果要使用gis等需要安裝對應的插件