无法从客户端连接到PostgreSQL-错误超时

问题描述 投票:0回答:1

很多天后,我试图连接到我的PostgreSQL实例,所以我决定该寻求帮助了。

我正在尝试从Windows计算机连接到我的PostgreSQL数据库。

我正在尝试pgAdmin 4和dBeaver,但是都无法连接。下面是使用dBeaver连接时收到的错误的屏幕截图。

enter image description here

我正在创建的连接就像这样:

enter image description here

我的用户是(\du):

                                 List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 umberto   | Superuser, Create role, Create DB                          | {}

我的数据库(\l):

                              List of databases
   Name    |  Owner   | Encoding | Collate |  Ctype  |   Access privileges
-----------+----------+----------+---------+---------+-----------------------
 postgres  | postgres | UTF8     | C.UTF-8 | C.UTF-8 |
 template0 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
           |          |          |         |         | postgres=CTc/postgres
 template1 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
           |          |          |         |         | postgres=CTc/postgres
 umberto   | umberto  | UTF8     | C.UTF-8 | C.UTF-8 |
 wondermap | postgres | UTF8     | C.UTF-8 | C.UTF-8 |

不知道确切的位置在服务器上搜索日志以解决此问题。我唯一能找到的是文件夹/var/log/postgresql,在该文件夹中我仅看到两个未压缩的文件,但消息所指的是我尝试进行连接之前的几天。

最后,我的pg_hba.conf

# Database administrative login by Unix domain socket
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
host    all             all             0.0.0.0/0               md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
host    all             all             ::0/0                   md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
host    all             all             ::/0                    md5

可能是什么问题?

postgresql database-connection pgadmin dbeaver
1个回答
0
投票

我通常不会查看postgres日志来解决连接超时错误,因为如果postgres拒绝连接,它们将立即被拒绝而不是给您超时,因此,如果您超时,通常表示它从未到达过postgres,因此日志中没有任何相关内容。

根据我的经验,连接超时错误通常是由于Windows /网络问题引起的,例如,服务器上(或服务器前面)的防火墙不允许访问端口5432,或者实际上没有监听端口5432 (可能是postgres并未实际运行,或者已配置为在其他端口上侦听,等等。)>

我最喜欢的用于在Windows上解决这类连接问题的工具是portqry。用法是portqry -n [hostname] -e [port number]。它将尝试连接到端口[hostname]上的[port number]并提供结果:

  • Listening:portqry能够在指定端口上连接到主机,并且应用程序正在该端口上侦听。这就是您想要的。
  • Not listening:portqry能够连接到指定端口上的主机,但是该端口上没有侦听任何内容。对于postgres,这可能是因为服务未运行或正在侦听其他端口。
  • Filtered:portqry无法连接到指定端口上的主机。这意味着它实际上被阻止了连接,这通常是由主机上或客户端与主机之间的防火墙引起的,这阻止了对该端口上主机的访问。
© www.soinside.com 2019 - 2024. All rights reserved.