默认情况下,PostgreSQL服务器仅监听本地接口127.0.0.1。要启用对 PostgreSQL 服务器的远程访问,请打开配置文件postgresql.conf并添加listen_addresses = '*' in the CONNECTIONS AND AUTHENTICATION部分。
sudo vim /etc/postgresql/10/main/postgresql.conf
/etc/postgresql/10/main/postgresql.conf
#------------------------------------------------------------------------------# CONNECTIONS AND AUTHENTICATION#------------------------------------------------------------------------------# - Connection Settings -listen_addresses='*' # what IP address(es) to listen on;
# TYPE DATABASE USER ADDRESS METHOD
# The user jane will be able to access all databases from all locations using a md5 password
host all jane 0.0.0.0/0 md5
# The user jane will be able to access only the janedb from all locations using a md5 password
host janedb jane 0.0.0.0/0 md5
# The user jane will be able to access all databases from a trusted location (192.168.1.134) without a password
host all jane 192.168.1.134 trust