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等需要安装对应的插件