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

查看:1885
本文介绍了无法在端口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天全站免登陆