gpt4 book ai didi

postgresql - 无法从 pgadmin4 连接到 postgresql ec2 实例

转载 作者:行者123 更新时间:2023-12-04 10:11:05 25 4
gpt4 key购买 nike

我创建了一个 EC2 实例,然后在其中安装了 postgresql(版本 11)和 timescaledb。我的安全组如下所示:

enter image description here

截至目前,我已为所有 IP 地址启用此实例。

我的 /etc/postgresql/11/main/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
# IPv6 local connections:
host all all ::1/128 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.0.0.0/0 md5 #ipv4 range
host all all ::0/0 md5 #ipv6 range
host all all all md5 #all ip

/etc/postgresql/11/main/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)

然后,我尝试使用 Public DNS(IPv4) 通过 Pgadmin4 连接到数据库。 : ec2-xx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com
enter image description here

我输入用户名和密码后,它抛出以下错误:
Unable to connect to server:

could not connect to server: Connection refused
Is the server running on host "ec2-xx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com" (xx.xxx.xxx.xxx) and accepting
TCP/IP connections on port 5432?

我查看了以下帖子并遵循了所有说明,但无济于事:
  • connect-to-remote-postgresql-server-on-amazon-ec2

  • 任何人都可以帮我解决这个问题吗?

    编辑 1

    当我做:
    /etc/init.d/postgresql restart

    我得到:
    [....] Restarting postgresql (via systemctl): postgresql.service==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
    Authentication is required to restart 'postgresql.service'.
    Authenticating as: Ubuntu (ubuntu)
    Password:

    我不知道在此处输入什么密码以便重新启动 postgresql

    最佳答案

    正如@jjanes 在评论中指出的那样,我必须重新启动 postgresql 才能访问它。

    正在做

    /etc/init.d/postgresql restart

    抛出错误(如问题所示),这就是我必须使用的原因
    sudo /etc/init.d/postgresql restart

    为了授予根访问权限。

    数据库重新启动后,我尝试通过 pgadmin4 再次连接到 ec2 实例,这次它起作用了。

    关于postgresql - 无法从 pgadmin4 连接到 postgresql ec2 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61331721/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com