postgresql13远程连接报错 Connection to 117.50.184.237:5432 refused. Check that the hostname and port are c

发布于:2023-09-14 ⋅ 阅读:(826) ⋅ 点赞:(0)

报错信息
Connection to hostname:port refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Connection refused: no further information
解决方案
修开配置文件

vim /var/lib/pgsql/13/data/postgresql.conf

添加以下内容并保存如图

listen_addresses = '*' 

在这里插入图片描述
重启

systemctl restart postgresql-13.service

再次连接
报错
FATAL: no pg_hba.conf entry for host “ip”, user “postgres”, database “postgres”, SSL off

这个错误通常表示PostgreSQL拒绝了来自IP地址为"27.38.212.47"的主机的连接请求,因为它在pg_hba.conf文件中没有相应的条目。

在pg_hba.conf文件中,定义了PostgreSQL的身份验证规则,控制哪些主机可以连接到PostgreSQL服务器以及使用哪种身份验证方法进行连接。如果客户端尝试连接PostgreSQL服务器,但其IP地址或身份验证方法不在pg_hba.conf文件中列出,则PostgreSQL将拒绝连接请求。

要解决此问题,您需要在pg_hba.conf文件中添加一条允许来自"27.38.212.47"的主机使用"postgres"用户连接到"postgres"数据库的条目。您可以按照以下步骤执行:

使用root用户登录到PostgreSQL服务器。

找到pg_hba.conf文件。在CentOS上,通常位于/var/lib/pgsql/13/data/pg_hba.conf。

使用文本编辑器打开pg_hba.conf文件。

在文件的底部添加以下行:

host    postgres    postgres    27.38.212.47/32    md5

这将允许来自IP地址为"27.38.212.47"的主机使用"postgres"用户连接到"postgres"数据库,使用md5加密的密码进行身份验证。

添加以下信息将允许任何主机连接

# TYPE  DATABASE        USER            ADDRESS          METHOD
host    all             all             0.0.0.0/0         trust

保存并关闭pg_hba.conf文件。

重新启动PostgreSQL服务器,以使更改生效:

sudo systemctl restart postgresql-13

可以正常连接了
在这里插入图片描述

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到