无法在端口 5432 上连接到 Postgresql [英] Can't connect to Postgresql on port 5432

查看:43
本文介绍了无法在端口 5432 上连接到 Postgresql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行 Ubuntu Server 14.04 的服务器上安装了 PostgreSQL 9.3.

I have PostgreSQL 9.3 installed on a server running Ubuntu Server 14.04.

如果我通过终端 ssh 进入服务器,我就可以连接 psql.但是当我尝试配置 pgAdmin III 进行远程连接时,我得到:

If I ssh into the server via terminal, I'm able to connect with psql. But when I try to configure pgAdmin III to do the remote connection, I get:

服务器不监听 服务器不接受连接:连接库报告无法连接到服务器:连接拒绝服务器是否在主机172.24.3.147"上运行并接受端口 5432 上的 TCP/IP 连接?

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 它给我:

When I run on the server service postgresql status it gives me:

9.3/main (port 5432): online

当然,我在这里遗漏了一些重要的东西.

So of course I'm missing something important here.

编辑

在服务器上运行 netstat -na 时,我得到(我猜是相关部分):

When running netstat -na on the server, I get (relevant portion, I guess):

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' 的行.

You have to edit postgresql.conf file and change line with 'listen_addresses'.

您可以在 /etc/postgresql/9.3/main 目录中找到该文件.

This file you can find in the /etc/postgresql/9.3/main directory.

默认的 Ubuntu 配置只允许 localhost(或 127.0.0.1)接口,当每个 PostgreSQL 客户端在同一台计算机上工作时,这足以使用作为 PostgreSQL 服务器.如果您想从其他计算机连接 PostgreSQL 服务器,您可以这样更改此配置行:

Default Ubuntu config have allowed only localhost (or 127.0.0.1) interface, which is sufficient for using, when every PostgreSQL client work on the same computer, as PostgreSQL server. If you want connect PostgreSQL server from other computers, you have change this config line in this way:

listen_addresses = '*'

然后你也编辑了 pg_hba.conf 文件.在此文件中,您已设置可以从哪些计算机连接到此服务器以及可以使用哪种身份验证方法.通常你需要类似的行:

Then you have edit pg_hba.conf file, too. In this file you have set, from which computers you can connect to this server and what method of authentication you can use. Usually you will need similar line:

host    all         all         192.168.1.0/24        md5

请阅读此文件中的评论...

Please, read comments in this file...

编辑 postgresql.conf 和 pg_hba.conf 后,您必须重新启动 postgresql 服务器.

After the editing postgresql.conf and pg_hba.conf you have to restart postgresql server.

突出显示的配置文件.

这篇关于无法在端口 5432 上连接到 Postgresql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆