【问题标题】:perl DBI->connect pops "no route to host" although i can pick hostperl DBI->connect 弹出“没有到主机的路由”虽然我可以选择主机
【发布时间】:2013-03-17 01:18:56
【问题描述】:

我有这个 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 上的连接。 我会因为登录凭据错误而收到此消息吗?

【问题讨论】:

  • 来自同一用户帐户和主机的psql -h 10.0.0.3 flows 怎么样?结果一样吗?
  • 连接运算符的冗余使用:"DBI:Pg:dbname=$dbname;host=$host" -- 插入标量变量。
  • No route to host 听起来像是来自操作系统本身的消息。 (我不知道是否有任何方法可以指定代理,但如果有并且如果你这样做了,那么有问题的主机可能是代理。)
  • 啊,我明白了。我有错误的 $dbname。我还按照 TLP 建议的方式编辑了我的脚本。

标签: perl postgresql dbi dbd


【解决方案1】:

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

第二次添加DBI->errstr以获得更正确的错误

我的 $dbh = DBI->connect("DBI:Pg:dbname=".$dbname.";host=".$host, $username, $pass, {'RaiseError' => 1}) 或死 DBI->errstr;

第三,您应该能够在从 DBI 尝试之前从命令行连接到 psql

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-12
    • 1970-01-01
    • 2019-03-08
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    相关资源
    最近更新 更多