安装PostgreSQL10数据库之后,默认只能本地访问连接。如果想在其他主机上访问PostgreSQL10数据库服务器,就需要对pg_hba.conf和postgresql.conf这两个文件进行配置。 所在目录如下:
- /var/lib/pgsql/10/data/
1.修改pg_hba.conf文件
在data/pg_hba.conf中
- 在data/pg_hba.conf中
- # TYPE DATABASE USER ADDRESS METHOD
- # IPv4 local connections:
- host all all 127.0.0.1/32 md5
- host all all 0.0.0.0/0 md5
2.修改postgresql.conf文件
在安装目录下data/postgresql.confi文件中将
- #listen_addresses='localhost’
修改为
- listen_addresses = '*'
修改完成后重启数据库
- root@localhost data]# systemctl restart postgresql-10
附:查看监听的端口
- [root@localhost data]# netstat -antpl
- Active Internet connections (servers and established)
- Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
- tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1286/cupsd
- tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 3985/postmaster
- tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1495/master
- tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 3079/sshd: root@pts
- tcp 0 0 0.0.0.0:8069 0.0.0.0:* LISTEN 4031/python3
- tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
- tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1775/dnsmasq
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1290/sshd
- tcp 0 0 10.128.25.135:5432 10.128.30.218:61157 ESTABLISHED 4041/postgres: post
- tcp 0 0 10.128.25.135:5432 10.128.30.218:61160 ESTABLISHED 4042/postgres: post
- tcp 0 0 10.128.25.135:5432 10.128.30.218:61161 ESTABLISHED 4043/postgres: post
- tcp 0 52 10.128.25.135:22 10.128.30.218:60051 ESTABLISHED 3079/sshd: root@pts
- tcp6 0 0 ::1:631 :::* LISTEN 1286/cupsd
- tcp6 0 0 :::5432 :::* LISTEN 3985/postmaster
- tcp6 0 0 ::1:25 :::* LISTEN 1495/master
- tcp6 0 0 ::1:6010 :::* LISTEN 3079/sshd: root@pts
- tcp6 0 0 :::111 :::* LISTEN 1/systemd
- tcp6 0 0 :::21 :::* LISTEN 1311/vsftpd
- tcp6 0 0 :::22 :::* LISTEN 1290/sshd