2

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

在此处输入图像描述

到目前为止,我已经为所有 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)

然后,我尝试使用以下命令通过 Pgadmin4 连接到数据库Public DNS(IPv4)ec2-xx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com

在此处输入图像描述

我输入用户名和密码后,它会抛出以下错误:

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?

我查看了以下帖子并按照所有说明进行操作,但无济于事:

  1. 连接到远程-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

4

1 回答 1

2

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

正在做

/etc/init.d/postgresql restart

抛出错误(如问题所示)这就是我必须使用的原因

sudo /etc/init.d/postgresql restart

为了授予root访问权限。

重新启动 db 后,我尝试通过 pgadmin4 再次连接到 ec2 实例,这次成功了。

于 2020-04-21T08:28:27.283 回答