perl DBI->连接弹出"no route to host"虽然我可以选择主机



我有这个perl脚本

wrapper.pl

#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use DBI;
# input params
my $end;
my $start;
my $url;
my @IP;
my $host = "localhost";
my $dbname = "flows";
my $username;
my $pass;
GetOptions      ("s|start=s" => $start,
                 "e|end=s" => $end,
                 "r|url=s" => $url,
                 "ip|iplist=s" => @IP,
                 "h|host=s" => $host,
                 "db|dbname=s" => $dbname,
                 "u|username=s" => $username,
                 "p|pass=s" => $pass);

# connect and send request to database
 my $dbh = DBI->connect("DBI:Pg:dbname=".$dbname.";host=".$host, $username, $pass, {'RaiseError' => 1});

当我运行

./wrapper.pl -h 10.0.0.3

我得到:

DBI connect('dbname=flows;host=10.0.0.3','',...) failed: could not connect to server: No route to host
Is the server running on host "10.0.0.3" and accepting
TCP/IP connections on port 5432?

我可以ping服务器,而且它应该接受5432上的连接。我可能会因为错误的登录凭据而收到此消息吗?

首先您应该在use DBI;之后use DBD::Pg;

其次加入DBI->errstr以获得更合适的误差

我的$ dbh = DBI ->连接("DBI: Pg: dbname = " $ dbname。";主机= "。美元的主机,$username, $pass, {'RaiseError' => 1}) or die DBI->errstr;

第三,你应该能够从命令行连接到psql,然后再尝试从DBI

psql -h 10.0.0.3 -U username -d dbname -p 5432(请检查语法)

相关内容

  • 没有找到相关文章

最新更新