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

前端之家收集整理的这篇文章主要介绍了perl – 没有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

原文链接:/Perl/173419.html

猜你在找的Perl相关文章