Why can't I connect to postgres from Perl? Why can't I connect to postgres from Perl? postgresql postgresql

Why can't I connect to postgres from Perl?


Rather than play 20 questions to debug your setup, DBI->errstr will say why the connection failed.

my $dbh = DBI->connect(...) or die DBI->errstr;

Though if I had to guess... since Postgres authenticates based on host and login user, I suspect the confusion lies between the user name you're giving to the Postgres connection and the Unix user you're logged in as.


Besides Schwern's excellent response, you can also check PostgreSQL log which, depending on the options selected in postgresql.conf may tell you a lot about what was wrong.


I had the same issue. The hint above for trying "-h localhost" confirmed that I had a problem connecting over the network.

Adding the following to pg_hba.conf fixed the problem.

host all postgres 127.0.0.1/32 trust