Postgresql客户端不能远程连接数据库服务器 org.postgresql.util.PSQLException:

Postgresql安装完成之后,默认情况下是不允许远程客户端直接连接的,并且默认的监听配置文件里边,监听的服务器地址是127.0.0.1即:localhost

报如下错误:

org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "<host_ip>", user "fkong", database "fkong", SSL off

因此我们需要修改两个地方,pg_hba.conf  postgresql.conf

odoo@odooV01:/etc/postgresql/9.6/main$ pwd
/etc/postgresql/9.6/main
odoo@odooV01:/etc/postgresql/9.6/main$ 
odoo@odooV01:/etc/postgresql/9.6/main$ ls
environment  pg_ctl.conf  pg_hba.conf  pg_ident.conf  postgresql.conf  start.conf
odoo@odooV01:/etc/postgresql/9.6/main$ 

(1)在PostgreSQL数据库的安装目录下找到pg_hba.conf, vi打开,找到

“# IPv4 local connections:”

在其下加上请求连接的机器IP

默认配置:host all all 127.0.0.1/32 md5

32是子网掩码的网段;md5是密码验证方法,可以改为trust

即:

host all all 你的客户端IP/32 trust

或者允许所有不同网段机器访问:

host all all 0.0.0.0/0 trust

 

(2) 同样在该目录下,vi 打开postgresql.conf文件 找到 listen_addresses = 'localhost' 这一行,

修改为:listen_addresses = '*'

 

(3) 重启postgresql服务,和其他服务一样还是用systemd进行管理:

切换到:postgres用户 执行重启服务操作:

systemctl stop postgresql-9.6 #停止服务
systemctl start postgresql-9.6 #启动服务
其他命令:
systemctl restart postgresql-9.6 #重启服务
systemctl enable postgresql
-9.6 #自动启动

service postgresql-10 start
或者(注意不同的版本指定不同版本号)
service postgresql-9.6 start

其他:

http://blog.csdn.net/ghostliming/article/details/53312493

http://www.jb51.net/article/53011.htm

http://www.jb51.net/article/104829.htm

http://blog.csdn.net/kongxx/article/details/5964638

http://francs3.blog.163.com/blog/static/4057672720138953548912/

posted @ 2017-06-21 16:30  hello-Jesson  阅读(1702)  评论(0编辑  收藏  举报