【问题标题】:pgadmin, postgres and gogole cloud connection time outpgadmin、postgres 和谷歌云连接超时
【发布时间】:2024-05-03 18:25:03
【问题描述】:

我关注了this tutorial

我设法设置了所有内容,并完全按照教程中的说明进行操作。

但是当我尝试使用 PGADMIN 4 连接到它时,我得到了连接时间并且我永远无法修复它。

然后我找到this link,里面有如下命令:

sudo -i -u postgres
psql
\conninfo

然后我可以看到以下消息:

You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".

所以我现在不明白什么是错的,当我输入时: sudo nano ../../etc/postgresql/9.3/main/pg_hba.conf 查看文件的内容并输入密码,密码不被接受。

然后我通过关闭窗口重新启动一切并再次打开它,然后我可以查看文件:

# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
# 
# 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
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5
# IPv4 remote connections for the tutorial:
#host     all             all             127.0.0.1/32           md5
#host     all             all             35.196.55.208/32       md5
host     all             all             all                     md5

我添加了最后 4 行来解决问题,但还没有。

我做错了什么?我正在查看许多教程,以及 Stack Overflow 的几页,但仍然没有!

【问题讨论】:

    标签: postgresql ubuntu google-cloud-platform pgadmin-4


    【解决方案1】:

    您没有提供远程连接的权限。

    在给定的教程中,Connecting remotely 部分明确提到您需要在pg_hba.conf 文件中提供您的 IP 地址。

    将 [YOUR_IPV4_ADDRESS] 替换为您本地计算机的地址。

    此外,在 Google Cloud Platform Console 的“实例”页面中,单击 实例以打开其概览页面。选择授权选项卡。 在授权网络下,单击添加网络并输入 IP 地址 安装客户端的客户端计算机。点击完成,然后 单击页面底部的保存以保存更改。连接至 您的实例,可以使用 SSL 也可以不使用 SSL。

    pg_hba.conf 文件中提供您的 IP 地址,重新启动 Postgres 服务并重试。

    【讨论】:

    • 127.0.0.1/32 这个ip也在那个文件里!
    • 我认为问题可能出在我的地址上,我不确定我是否使用了正确的地址!
    • 127.0.0.1/32 用于本地主机(即安装在同一台机器上的 pgadmin 和 postgres)连接,您必须提供 IP 地址才能远程连接。如果可以确认您可以从任何地方访问您的计算机,那么您可以尝试添加host all all 0.0.0.0/0 md5,但出于安全原因我不建议这样做。
    • 我提出了这个问题*.com/questions/47789411/… 我想我解释得更好!
    • 我与 IPV4 地址/32 建立了远程连接。我删除了最后 3 行,只写了 1 行!