#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    59
    Rep Power
    6

    How to set paths used by CPAN on SuSE machine?


    I have a program I built to do some work with files we receive on our FTP server (SuSE 9.0) and use them to make changes to a Postgresql database on another system. When I first ran it, I discovered that I did not have the DBD::Pg module I needed to interact with our database on it - my test server had no problems, but we didn't use postgres on the FTP server for anything previously.

    Attempting to use CPAN to get the module in question returns an error, which I have attempted to copy in full (from the start of the error segment) below:

    Code:
      CPAN.pm: Going to build T/TU/TURNSTEP/DBD-Pg-2.19.3.tar.gz
    
    Configuring DBD::Pg 2.19.3
    PostgreSQL version: 70304 (default port: 5432)
    POSTGRES_HOME: (not set)
    POSTGRES_INCLUDE: /usr/include/pgsql
    POSTGRES_LIB: /usr/lib
    OS: linux
    
    ****************
    WARNING! DBD::Pg no longer supports versions less than 7.4.
    You must upgrade PostgreSQL to a newer version.
    ****************
    
    Running make test
      Make had some problems, maybe interrupted? Won't test
    Running make install
      Make had some problems, maybe interrupted? Won't install
    Okay, turns out the FTP machine did have a copy of Postgres 7.3 on it. I didn't think that would be a big problem - I could simply download a more up-to-date copy of postgres and install it, and things would be good.

    I've done so - from source install of Postgres 8.3.23, added the path to my $PATH variable, and verified that running psql shows as version 8.3.23. However, this version of Postgres installed to a different directory than the previous one did, and I think I've managed to miss something in the path settings - I'm still getting the same error as above in CPAN when I try to download the DBD::Pg module.

    What do I need to do to alter the path settings, either of my own path variable or of CPAN's path searching, to have it point to the new version of Postgres (or whatever libraries it may want from that) instead of the old one?
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,262
    Rep Power
    1810
    Can only answer in general terms since I don't use SUSE.

    There are a few hints in the DBD::Pg README file.

    By default Makefile.PL uses App::Info to find the location of the
    PostgreSQL library and include directories. However, if you want to
    control it yourself, define the environment variables POSTGRES_INCLUDE
    and POSTGRES_LIB, or define just POSTGRES_HOME. Note that if you have
    compiled PostgreSQL with SSL support, you must define the POSTGRES_LIB
    environment variable and add "-lssl" and "-lcrypto" to it, like this:

    export POSTGRES_LIB="/usr/local/pgsql/lib -lssl -lcrypto"
    So you can define those environment variables right in the shell before you run CPAN. The other variables mentioned in your post should be set also, but they are only needed for the automated tests.

    The tests rely on being able to connect to a valid Postgres database.
    The easiest way to ensure this is to set the following environment variables:

    DBI_DSN=dbi:Pg:dbname=<database>
    DBI_USER=<username>
    DBI_PASS=<password>

    If you are running on a non-standard port, you must set PGPORT or
    add the port to the DBI_DSN variable like this:

    DBI_DSN='dbi:Pg:dbname=<database>;port=<port#>'
    ---

    As far as having two versions of postgres on one machine, if that wasn't intended, you can edit the postgres makefile to specify where you want the install to occur. Just add the --prefix option when running configure. List of options in the docs.

    If you are running two versions of postgres on the same machine, you can run them both at the same time by setting one to use a different port, or you can only run one at a time. You will have to choose which method to use.

    --

    Although you can set the environment variables directly from the command line and get CPAN to find the desired version of postgres this time, remember that as soon as that shell session ends, the environment variables will be lost. The next time you log in you will have to set them again in order to use the right DB by default.

    You can avoid that by setting up your shell to define those variables at startup. Example, if you use zsh, you can edit ~/.zshrc to include something like
    Code:
    export PGDATA="/data/pgdata"
    export PGHOME="/usr/lib/pgsql"
    export PATH="$PGHOME/bin/:$PATH"
    Whatever the locations are for the version of postgres you want to use.

    If you or a program does not specify the full path, this path variable is used to look for a match. By putting the path to the new version of postgres first, that's the one that will be found when you simply type something like 'psql'.

IMN logo majestic logo threadwatch logo seochat tools logo