Question

I have this perl script

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});

When i run

./wrapper.pl -h 10.0.0.3

I get :

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?

I can ping the server and also it should accept connections on 5432. May I get this message because of bad login credentials?

Was it helpful?

Solution

First you should use DBD::Pg; after use DBI;

Secondly add DBI->errstr for more proper error

my $dbh = DBI->connect("DBI:Pg:dbname=".$dbname.";host=".$host, $username, $pass, {'RaiseError' => 1}) or die DBI->errstr;

Third you should be able to connect to psql from commandline before triyng from DBI

psql -h 10.0.0.3 -U username -d dbname -p 5432 (Please check syntax)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top