【发布时间】:2025-12-12 17:00:02
【问题描述】:
在 Ubuntu 16.04 上运行 Postgresql 9.5。
我的 /etc/postgresql/9.5/main/pg_hba.conf:
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
#remote connection
host all all 0.0.0.0/0 trust
我的/etc/postgresql/9.5/main/postgresql.conf:
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
# - Security and Authentication -
#authentication_timeout = 1min # 1s-600s
#ssl = true # (change requires restart)
#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
# (change requires restart)
我的 netstat -nlp | grep 5432:
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 22621/postgres
tcp6 0 0 :::5432 :::* LISTEN 22621/postgres
unix 2 [ ACC ] STREAM LISTENING 10261951 22621/postgres /var/run/postgresql/.s.PGSQL.5432
我可以在本地连接,但无法远程连接。当我尝试从另一台计算机连接时,命令超时。
【问题讨论】:
-
您确定没有设备等阻止 TCP 5432?当您从远程计算机 telnet 到 TCP 5432 时会发生什么?
-
telnet
5432 --> Trying XXX.XXX.XX.XXX........连接超时 -
我还按照@Z4-tier 的建议禁用了防火墙
标签: postgresql ubuntu-16.04 postgresql-9.5