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

perl – 没有pg_hba.conf条目的主机

发布时间:2020-12-15 21:26:00 所属栏目:大数据 来源:网络整理
导读:我得到以下错误,当我尝试使用DBI连接 DBI connect('database=chaosLRdb;host=192.168.0.1;port=5433','postgres',...) failed: FATAL: no pg_hba.conf entry for host "192.168.0.1",user "postgres",database "chaosLRdb",SSL off 这里是我的pg_hba.conf文
我得到以下错误,当我尝试使用DBI连接
DBI connect('database=chaosLRdb;host=192.168.0.1;port=5433','postgres',...) 
failed: FATAL:  no pg_hba.conf entry for host "192.168.0.1",user "postgres",database "chaosLRdb",SSL off

这里是我的pg_hba.conf文件:

# "local" is for Unix domain socket connections only
local   all         all                               md5
# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
# IPv6 local connections:
host    all         all         ::1/128               md5

host    all         postgres    127.0.0.1/32          trust

host    all        postgres     192.168.0.1/32        trust

host    all        all         192.168.0.1/32        trust

host    all        all         192.168.0.1/128        trust

host    all        all         192.168.0.1/32        md5

host    chaosLRdb    postgres         192.168.0.1/32      md5
local    all        all         192.168.0.1/32        trust

我的perl代码是

#!/usr/bin/perl-w
use DBI;
use FileHandle;

print "Start connecting to the DB...n";

@ary = DBI->available_drivers(true);
%drivers = DBI->installed_drivers();
my $dbh = DBI->connect("DBI:PgPP:database=chaosLRdb;host=192.168.0.1;port=5433","postgres","chaos123");

我可以知道我在这里想念什么吗?

解决方法

这是一个老问题,但我正在寻找同样的问题的帮助,并注意到问题中指定的pg_hba.conf文件的一些问题。对于后代我以为我会回答。

在pg_hba.conf文件中,我看到一些不正确和混乱的行:

# fine,this allows all dbs,all users,to be trusted from 192.168.0.1/32
# not recommend because of the lax permissions
host    all        all         192.168.0.1/32        trust

# wrong,/128 is an invalid netmask for ipv4,this line should be removed
host    all        all         192.168.0.1/128       trust

# this conflicts with the first line
# it says that that the password should be md5 and not plaintext
# I think the first line should be removed
host    all        all         192.168.0.1/32        md5

# this is fine except is it unnecessary because of the previous line
# which allows any user and any database to connect with md5 password
host    chaosLRdb  postgres    192.168.0.1/32        md5

# wrong,on local lines,an IP cannot be specified
# remove the 4th column
local   all        all         192.168.0.1/32        trust

我怀疑,如果你md5的密码,这可能工作,如果你修剪线。要获取md5,您可以使用perl或以下shell脚本:

echo -n 'chaos123' | md5sum
 > d6766c33ba6cf0bb249b37151b068f10  -

所以,你的连接线会喜欢:

my $dbh = DBI->connect("DBI:PgPP:database=chaosLRdb;host=192.168.0.1;port=5433","chaosuser","d6766c33ba6cf0bb249b37151b068f10");

有关更多信息,这里是documentation of postgres 8.X’s pg_hba.conf file。

(编辑:李大同)

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

    推荐文章
      热点阅读