Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Trouble establishing a dialogue between Perl and PostgreSQL

by DigitalKitty (Parson)
on Jan 14, 2008 at 20:14 UTC ( #662370=perlquestion: print w/replies, xml ) Need Help??
DigitalKitty has asked for the wisdom of the Perl Monks concerning the following question:

Hi all.

I recently upgraded my PostgreSQL install to version 8.2.6 (win32). After doing so, I installed the following modules (DBI was installed previously).

When attempting to connect to a database with DBD::Pg, the connection hung and only by pressing Ctrl-C was I able to terminate the program.

Assuming something might be wrong with the module, I tried DBD::PgPP in a very simple test script (please see below):
#!/usr/bin/perl use warnings; use strict; use DBI; my $db = DBI->connect('dbi:PgPP:testdb', 'postgres', 'xxxxxxxxx'); if( $db ) { print "Connected!\n"; } else { print "Nope. Sorry.\n"; }

After doing so, I immediately noticed the following message:
C:\Perl2\bin>perl DBI connect('testdb','postgres',...) failed: Couldn't connect to /tmp/ +.s.PGSQL.5432: at C:/Perl2/site/lib/DBD/ line 124 at test_pg.p +l line 5

Is there a configuration setting I need to modify? For testing purposes, I was able to connect to the database with both python and ruby.



Replies are listed 'Best First'.
Re: Trouble establishing a dialogue between Perl and PostgreSQL
by erix (Vicar) on Jan 14, 2008 at 21:08 UTC

    I wouldn't bother with that old unmaintained DBD::PgPP if not necessary.

    For DBD::Pg, which is very actively maintained, there is a ppm/binary for DBD::Pg here:

    If you download a local copy and give the local directory to PPM, it should install it without problem.

    If some problem persists, don't assume the module DBD::Pg is at fault, it's probably something else: read the postgres log, it will probably bring enlightenment.

    Ah, and by the way: PostgreSQL 8.3 Release Candidate 1 is out! You may want to try that - it is already very stable, and full of new goodies: see release notes for 8.3.

    For win32: v8.3RC1 binaries

    update: 8.3 binaries ( PostgreSQL 8.3 was released 4 february 2008 ).

Re: Trouble establishing a dialogue between Perl and PostgreSQL
by talexb (Canon) on Jan 14, 2008 at 21:15 UTC

    Under Linux (the Windows locations will, no doubt, vary) I usually have to go into /var/lib/pgsql/data/ and modify pg_hba.conf (to allow local access without authentication) and postgresql.conf (to allow a connection using sockets).

    And, of course, if this is a new installation I have to run the service script with initdb before the service itself can be started. You platform may vary.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: Trouble establishing a dialogue between Perl and PostgreSQL
by olus (Curate) on Jan 14, 2008 at 20:47 UTC
    Maybe you need to specify that you are connecting to localhost, and you mustn't forget about dbname.
    my $db=DBI->connect("dbi:PgPP:dbname=testdb;host=localhost", 'postgres +','xxxxxxxxx') or die DBI->errstr;
    Hope that helps.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://662370]
Approved by kyle
[1nickt]: my $x = $aohoaoh->[0]->{' foo'}->[0]->{'bar' }; should work
[thepkd]: not indexing
[thepkd]: getting data out of the ds
[choroba]: it depends. Give more details, please
[thepkd]: i used a series of {}'s but it dont work
[choroba]: You need square brackets for arrays
[GotToBTru]: you can certainly construct a single expression to access any part of the data structure, without using temp variables. but you might make it easier on yourself and any other poor soul who has to understand your code if you do
[thepkd]: to dereference i mean
LanX .oO( oh tempz, oh moretz)
[thepkd]: @GotToBTru Sure. But.

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2016-12-06 13:25 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (104 votes). Check out past polls.