加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – “psql:无法连接到服务器:连接被拒绝”连接到远

发布时间:2020-12-13 16:35:11 所属栏目:百科 来源:网络整理
导读:我正在尝试使用以下命令连接到安装在远程服务器中的postgres数据库: psql -h host_ip -U db_username -d db_name 发生以下错误: psql: could not connect to server: Connection refused Is the server running on host “” and accepting TCP/IP connect
我正在尝试使用以下命令连接到安装在远程服务器中的postgres数据库:

psql -h host_ip -U db_username -d db_name

发生以下错误:

psql: could not connect to server: Connection refused
Is the server running on host “” and accepting
TCP/IP connections on port 5432?

> Postgres安装版本是9.4。
>主机操作系统:Ubuntu 15.04
>客户端操作系统:Centos 7

我已经尝试了以下但问题仍未解决:

>编辑包含的pg_hba.conf文件

host all all 0.0.0.0/0 md5

>编辑’postgresql.conf’并将listen参数更改为

listen_addresses=’*’

>重新启动postgres服务。
>在主机和客户端上禁用防火墙和iptables。
>我通过在本地运行psql命令来检查它是否有效。
>我尝试了这个question中给出的第二个解决方案。运行nmap给了我以下输出:

启动Nmap 6.47(http://nmap.org)于2015-09-07 18:08 IST
Nmap扫描报告为10.17.250.250
主机已启动(延迟0.0000040秒)。
未显示:997个封闭端口
港口国服务
22 / tcp打开ssh
25 / tcp打开smtp
80 / tcp打开http

我错过了什么。希望有人能提供帮助。

cd /etc/postgresql/9.x/main/

打开名为postgresql.conf的文件

sudo vi postgresql.conf

将此行添加到该文件

listen_addresses = '*'

然后打开名为pg_hba.conf的文件

sudo vi pg_hba.conf

并将此行添加到该文件

host  all  all 0.0.0.0/0 md5

它允许使用加密密码访问所有用户的所有数据库

重启你的服务器

sudo /etc/init.d/postgresql restart

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读