码迷,mamicode.com
首页 > 其他好文 > 详细

postgres登录失败Connection refused与SSL off失败

时间:2020-02-28 20:59:02      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:database   建立   增加   解决方法   oca   就是   参数   host   serve   

连接失败问题

使用postgres数据库连接工具测试,遇到两次失败

第一个登录失败问题

Connection to 192.168.XX.XX:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
  Connection refused: connect
  Connection refused: connect

这语句翻译下,用户名密码是正确的,但是tcp/ip的连接失败了。这个解决方法其实就是去建立tcp/ip连接过程。
原因是宿主机并没有监听其他的主机接口,因此没有建立连接。
解决方法

修改/var/lib/pgsql/9.6/data/postgresql.conf  
新增listen_addresses = '*'  #what IP address(es) to listen on
#默认
listen_addresses = 'localhost'

第二个登录失败问题

The server doesn't grant access to the database: the server reports 
FATAL: no pg_hba.conf entry for host "192.168.X.X", user "postgres", database "postgres"
#FATA:no pg_hba.conf entry for host "192.168.113.1",user "postgres",database "postgres",SSL off

这个问题也说这个主机没有权限访问数据库,也告诉配置文件在哪:pg_hba.conf。
pg_hba.conf为PostgreSQL的访问策略配置文件,默认位于/var/lib/pgsql/9.6/data/pg_hba.conf目录(postgres 9.6)。
该配置文件有5个参数,分别为:TYPE(主机类型)、DATABASE(数据库名)、USER(用户名)、ADDRESS(IP地址和掩码)、METHOD(加密方法)。
关于这个配置文件可以参考PostgreSQL的pg_hba.conf文件讲解
解决方式增加选项支持所所有的主机ip访问
增加

host    all             all             0.0.0.0/0               md5

postgres登录失败Connection refused与SSL off失败

标签:database   建立   增加   解决方法   oca   就是   参数   host   serve   

原文地址:https://www.cnblogs.com/JuncaiF/p/12378645.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!