我有一个postgres数据库,目前正在我的电脑上工作。我正在部署一个烧瓶应用程序,它使用上述数据库到linux服务器上,并且需要从linux机器远程连接到我的数据库。我在linux机器上使用的命令是
psql -h 12.345.678.901 -p 5432 -U postgres
其中12.345.678.901是我的本地PC ip地址。当我这样做的时候,我得到了错误
psql: error: connection to server at "12.345.678.901", port 5432 failed: Connection timed out
Is the server running on that host and accepting TCP/IP connections?
我想强调的是,这种连接并不是被“拒绝”,它只是超时(不像许多与这个主题相关的问题)。我不确定这是否有助于确定潜在的问题。我知道这是一个非常普遍的问题,但没有解决办法对我有效。这些解决方案包括更新pg_hba.conf、postgresql.conf、防火墙配置和许多其他解决方案。我做过这件事。我的pg_hba.conf文件如下所示
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all scram-sha-256
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::1/128 scram-sha-256
host all all ::0/0 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all scram-sha-256
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
host all all 0.0.0.0/0 md5
我的postgresql.conf看起来像这样
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
这些文件位于C:\Program \PostgreSQL\14\data中。我手动检查了这些更改是否保存并使用psql实现。在对这些文件进行了所有更改之后,我还重新启动了postgres。
我已经实现的其他修复:
的入站和出站TCP连接
'sudo允许5432/tcp‘和'sudo允许postgres/tcp'
。
我想不出这是为了救我的命。任何帮助都是非常感谢的。
发布于 2022-10-22 02:28:35
对于其他为这个问题而挣扎的人来说,经过数周的挖掘,我终于找到了解决办法。必须在postgres配置文件中使用的ip地址是路由器的ip地址。我试过我电脑上的每一个ip地址,但没有一个能工作。只有当我上了我的互联网提供商应用程序,发现我的路由器ip时,我终于能够连接。这方面最大的启示是,当我将ssh插入我的远程服务器时,它会说‘来自{路由器ip地址}的连接’。希望这能有所帮助。
https://stackoverflow.com/questions/73760536
复制相似问题