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

标签 postgresql database-connection pgadmin dbeaver

许多天后,我试图连接到我的 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我只看到两个非 gzipped 文件,但消息指的是我尝试连接之前的几天。

最后,我的 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

可能是什么问题呢?

最佳答案

我通常不会查看 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 无法连接到指定端口上的主机。这意味着它实际上被阻止连接,这通常是由主机上或客户端和主机之间的防火墙引起的,这阻止了对该端口上的主机的访问。
  • 关于postgresql - 无法从客户端连接到 PostgreSQL - 错误超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58588571/

    相关文章:

    PostgreSQL 9.4 数据库无法使用 pgAdmin 3 (Windows 8.1) 保存

    sql - 如何使用参数/变量并一起解释

    mysql - 将 MySql 转换为 PostgreSQL

    postgresql - 'select' 附近的 Knex.js SQL 语法错误

    sql - 表中每天的值总和

    oracle - 数据库连接断开时在经典ASP中使用自定义错误消息

    ios - 在 iOS 应用程序中从 sqlite3 获取没有行

    postgresql - dbeaver 7.1.1 删除数据库

    c++ - 在 Qt (C++) 中创建 SQLite 数据库

    postgresql - 适用于 Ubuntu 16.04 的 PgAdmin3 1.20 版本