我在运行 Ubuntu Server 14.04 的服务器上安装了 PostgreSQL 9.3。
如果我通过终端 ssh 进入服务器,我就可以连接到 psql。但是当我尝试配置 pgAdmin III 进行远程连接时,我得到:
Server doesn't listen The server doesn't accept connections: the connection library reports could not connect to server: Connection refused Is the server running on host "172.24.3.147" and accepting TCP/IP connections on port 5432?
当我在服务器上运行时 service postgresql status
它给我:
9.3/main (port 5432): online
所以我当然遗漏了一些重要的东西。
编辑
在服务器上运行 netstat -na
时,我得到(我猜是相关部分):
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
tcp 0 0 172.24.3.147:22 172.24.3.240:61950 ESTABLISHED
tcp 0 0 172.24.3.147:22 172.24.3.240:60214 ESTABLISHED
最佳答案
您必须编辑 postgresql.conf 文件并更改带有“listen_addresses”的行。
您可以在 /etc/postgresql/9.3/main
目录中找到此文件。
默认的 Ubuntu 配置只允许本地主机(或 127.0.0.1)接口(interface),当每个 PostgreSQL 客户端在同一台计算机上作为 PostgreSQL 服务器工作时,这足以使用。如果你想从其他计算机连接 PostgreSQL 服务器,你必须以这种方式更改此配置行:
listen_addresses = '*'
然后你也编辑了pg_hba.conf文件。在此文件中,您已设置可以从哪些计算机连接到此服务器以及可以使用哪种身份验证方法。通常你需要类似的行:
host all all 192.168.1.0/24 md5
请阅读此文件中的注释...
编辑:
在编辑 postgresql.conf 和 pg_hba.conf 后,您必须重新启动 postgresql 服务器。
EDIT2:突出显示的配置文件。
关于postgresql - 无法连接到端口 5432 上的 Postgresql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38466190/