arush_pareek has asked for the wisdom of the Perl Monks concerning the following question:

Pasted below is the script I am using for connecting to postgres . ----------------------------------------------------- cat tt.pl
#!/usr/bin/perl use DBI; my $dbh = DBI->connect('dbi:Pg:dbname=postgres;host=laddakh','postgres +','postgres',{AutoCommit=>1,RaiseError=>1,PrintError=>0});
But it gives me error as below :-
DBI connect('dbname=postgres;host=laddakh','postgres',...) failed: cou +ld not connect to server: Connection refused Is the server running on host "laddakh" and accepting TCP/IP connections on port 5432? at tt.pl line 5
my postgres is installed on a server name 'laddakh'.

Replies are listed 'Best First'.
Re: Error while connecting to postgres through DBI
by wind (Priest) on Jun 09, 2011 at 05:30 UTC

    laddakh is not going to be an acceptable hostname.

    Try an IP address or 'localhost' if it's the local machine.

    To make quicker work of it, I would suggest connecting to the db via the command prompt first, to be sure you have the settings right.

      laddakh is not going to be an acceptable hostname.

      Actually, the error message proves that your assumption is not correct. The error says "Connection refused". That specifically means that a TCP connection was successful in reaching the target host (IP address) but that the specified port number was not listening for incoming connections. So the host name ('laddakh') is one part of the connection spec that we can be certain is not invalid.

      Since many people are not aware of the precise meaning of "Connection refused", the error even elaborates quite a bit about it in hopes or helping out:

      could not connect to server: Connection refused Is the server running on host "laddakh" and accepting TCP/IP connections on port 5432?

      So this means that no postgresql server is running on the (valid) host 'laddakh' at port 5432. Possible explanations:

      1. The postgresql server software has not been installed there yet
      2. The postgresql server is simply not running at the moment and just needs to be started
      3. The postgresql server has been configured to use a TCP port other than the default of 5432
      4. The postgresql server has been configured to not use any TCP port at all
      5. The server is up and running, just on a host other than 'laddakh'.

      - tye        

        6. postgres is running but 5432 is blocked by a firewall

        Cheers, Chris