【问题标题】:How to let Postgres accept remote connections如何让 Postgres 接受远程连接
【发布时间】:2015-06-21 07:59:25
【问题描述】:

我正在尝试设置 Postgres 服务器,我需要它能够接受远程连接。

当我从客户端建立远程连接时,我不断出现此错误:

Connection to 192.168.1.6:5432 refused.
Check that the hostname and port are correct and that the postmaster is accepting TCP/IP

我已经用这些行编辑了文件pg_hba.conf

host all all 0.0.0.0/0 md5

host all all ::/0 md5

为了接受每个远程连接。
我还编辑了文件postgresql.conf,将监听地址设置为*

我该如何解决这个问题?

【问题讨论】:

  • 错误消息指示Check that the hostname and port are correct。你是否?您的 Postgres 实例是否使用端口 5432? (SHOW port;) 客户端是否在同一个网络中? (192.168.1.6 是一个 LAN 地址,从 Internet 上看不到,我想您知道吗?)您是否在更改为 postgresql.conf 后重新加载?如果问题仍然存在,请发布完整的 pg_hba.conf 文件(不带引号部分)。

标签: postgresql database-connection postgresql-9.4


【解决方案1】:

ssh 到您的服务器并发出命令netstat -tlpn | grep 5432 你应该得到类似的输出

tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 31309/postmaster tcp 0 0 :::5432 :::* LISTEN 31309/postmaster

这意味着 postgres 已准备好接受端口 5432 上的远程连接。否则您需要重新检查 postgresql.conf 中的侦听参数并重新启动 postgresql 集群(而不是重新加载)。 如果仍然无法远程访问,请尝试暂时禁用服务器和客户端上的防火墙iptables -F

【讨论】:

    猜你喜欢
    • 2017-10-17
    • 1970-01-01
    • 1970-01-01
    • 2014-07-06
    • 2012-04-25
    • 1970-01-01
    • 2010-10-30
    • 2022-01-26
    • 1970-01-01
    相关资源
    最近更新 更多