linuxperldbidbd-pg

Can I access Postgre database on another machine using Perl, DBI, and DBD::Pg?


Is this what I need? This is on my system.

lrwxrwxrwx 1 root root   12 May  1 20:05 /usr/lib/libpq.so.4 -> libpq.so.4.1*
-rwxr-xr-x 1 root root 130K Feb 27 07:36 /usr/lib/libpq.so.4.1*

Goal: I want to grab data from a Postgres server on another machine. I already have a db username, password, IP for the db machine.

Using cpanm I installed DBI just fine, no errors. When I installed DBD::Pg I got an error. CPAN error log follows:

cpanm (App::cpanminus) 1.6941 on perl 5.008008 built for i386-linux-thread-multi
Work directory is /root/.cpanm/work/1405531191.27414
You have make /usr/bin/make
You have LWP 6.04
You have /bin/tar: tar (GNU tar) 1.15.1
You have /usr/bin/unzip
Searching DBD::Pg on cpanmetadb ...
--> Working on DBD::Pg
Fetching http://www.cpan.org/authors/id/T/TU/TURNSTEP/DBD-Pg-3.3.0.tar.gz
-> OK
Unpacking DBD-Pg-3.3.0.tar.gz
Entering DBD-Pg-3.3.0
Checking configure dependencies from META.yml
Checking if you have version 0 ... Yes (0.88)
Checking if you have DBI 1.614 ... Yes (1.631)
Configuring DBD-Pg-3.3.0
Running Makefile.PL
Path to pg_config?
No POSTGRES_HOME defined, cannot find automatically
Configuring DBD::Pg 3.3.0
-> N/A
-> FAIL Configure failed for DBD-Pg-3.3.0. See /root/.cpanm/work/1405531191.27414/build.log for details.

If I get this working, my first step is to show just very basic info about the DBI driver. Next step would be to show a few fields from one table in a SELECT statement.

I won't be returning millions of records, but returning 100 records is certainly in the ballpark.

Thank you!


Solution

  • If you use the package that is already built and available for your system, then you won't have any of these problems.

    $ sudo yum install perl-DBD-Pg
    
    ... Lots of output snipped ...
    
    Dependencies Resolved
    
    ================================================================================
     Package              Arch        Version              Repository          Size
    ================================================================================
    Installing:
     perl-DBD-Pg          x86_64      1.49-4.el5_8         centos-update      115 k
    Installing for dependencies:
     postgresql-libs      x86_64      8.1.23-6.el5_8       centos-update      197 k
    
    Transaction Summary
    ================================================================================
    Install       2 Package(s)
    Upgrade       0 Package(s)
    
    Total download size: 312 k
    Is this ok [y/N]: 
    

    My example uses Centos 5.8.8, but it should work just the same for RHEL.