Installation of the DBD::Oracle perl module with Oracle instantclient under linux


French version

1) Overview

The DBD::Oracle module enable connectivity to an Oracle database from perl through DBI ( the perl generic Database Interface )

This document describe a simple and general way to make the perl module DBD::Oracle running up on any recent linux distribution ( x86 architecture).

The  traditional DBD::Orcale building process rely on the installation of a full Oracle Developpement environment. The problem is that the Oracle Developper Suite can only be installed on the RedHat ES/AS 3 or the UnitedLinux 1.0 distributions and that this environment is very heavy, too much for what we need.

Hopefully, Oracle has recently released a lighter package containing their client driver for linux. This package is called instantclient and we will rely on it to set up the DBD::Oracle module.

This method have been successfully tested with the 10.1.0.3 release of Oracle Instant client 10g
and with the linux distributions: Debian 3.1 (Sarge) and RedHat AS3.



Schema situant DBD::Oracle

2) Prerequisities

Before going further, check you have :

3) Oracle driver (instantclient) installation

The client-side Oracle drivers (proprietaries) for linux are downloadable at the address:
Oracle Instant Client pour linux (x86)

Rendez-vous on this page and download the 2 packages:
At the date of writing this document, only RedHat pakages ( .rpm ) are available.

In order to install theese packages on a ReadHat or any other rpm based distribution (Suze, Mandrake...), open a console as root and enter:

# rpm -ihv package.rpm

With a distribution that doesn't manage rpm packages, use the rpm2cpio tool:

# cd /
# rpm2cpio chemin/paquet.rpm | cpio -idmv


Update: As of the 12 October 2005, oracle ship a .zip file for the instantclient distribution.
There is no problem with that but .zip archives don't support the symbolic links. In order to permit the linker (ld) to found the instant client libraries, after unpacking the instantclient from the .zip file, you must create the symbolic links by yourself.

For exemple, to set the 10.1 version to the default version to link with:

# ln -s libclntsh.so.10.1 libclntsh.so
# ln -s libocci.so.10.1 libocci.so



4) Compilation and installation of the DBD::Oracle module

4.1) Get the module source with CPAN:


Open a console as root, and enter:

#perl -MCPAN -e shell

at CPAN prompt, enter:

cpan> get DBD::Oracle
cpan> quit

Now, CPAN should have fetch the latest DBD::Oracle source release ( at the date of writing this document, this is the 1.16 release ) in the /root/.cpan/build directory ( depending of your CPAN configuration, but in all cases, CPAN print on the console where it have unpacked the source )

4.2) Copy and adaptation of Makefile-instantclient

When building the module by the classical way, the automatic build and install script ( Makefile.PL ) try to determine the location of the Oracle C interface files (.h) as well as the libraries needed by the DBD::Oracle module.
However, as we don't have this complete Oracle developpement environement, the classical script can't cope with our instantclient  and we fail. So we will use another ( simplistic )  script to buid the module.

Download and copy this file : Makefile-instantclient.PL in the  /root/.cpan/build/DBD-Oracle-x.xx directory ( or the  analog directory depending on your CPAN configuration)

Copy this file : oracle-instantclient-config into the /usr/bin directory.
 
Note: You can, according to your preferences ( or constraints ) put this script in another directory ( like  /usr/local/bin, /opt/oracle_instantclient/bin, etc...  In this case, be sure that the directory in which you put the script appear in the PATH environment variable.

Set proper acces rights:
# chmod 755 /usr/bin/oracle-installclient-config

If you don't have installed the instantclient in the default emplacement ( default prefix is /usr/ ) you must edit le the oracle-instantclient-config file to set the prefix variable ( at line 4 ) so that  it reflect the prefix you have used.


4.3)  Compilation

  From the /root/.cpan/DBD-Oracle-x.xx directory, enter :

$ perl Makefile-instantclient.PL
$ make


Some tips in case of errors:



- If the compilator (gcc) vous dit say that it can't found headers (.h),

enter:
$ oracle-instantclient-config --cflags

and check that the instantclient header files are located in the returned directory ( after the -I parameter)

- If the linker (ld) complains about missing libraries (*.so.*),

enter:
$ oracle-instantclient-config --libs

and check that the instantclient libraries are located in the returned directory ( after the -L  parameter)

In case of one of the two checks failes, go back to the 4.2 step to correctly adapt the oracle-instantclient-config file.



4.4) Installation


Asroot, simply do :

# make install

If everything goes well, your DBD::Oracle module should be ready !

5) Test

 Copy this test script  (test_dbd_oracle.pl):

#!/usr/bin/perl

$oracle_server="server";
$oracle_listener="listener";
$oracle_sid="SID";
$oracle_port="PORT";
$oracle_user="user";
$oracle_password="password";
$oracle_testing_table="TABLE";

use DBI;
use DBD::Oracle;

my $dbh = DBI->connect("dbi:Oracle:host=$oracle_server;port=$oracle_port;sid=$oracle_sid",
                                           $oracle_user, $oracle_password)
  or die "Impossible de se connecter à la base Oracle : " . DBI->errstr;

my $sth = $dbh->prepare("SELECT * FROM $oracle_testing_table")
  or die "Impossible de preparer la requette: " . $dbh->errstr;

$sth->execute()
  or die "Impossible d'exécuter la requette: " . $sth->errstr;

while ( my @data = $sth->fetchrow_array() )
{
    my $firstname = $data[1];
    my $id = $data[2];
    print "\t$id: $firstname $lastname\n";
}

if ($sth->rows == 0)
{
    print "Table vide\n";
}

$sth->finish;

$dbh->disconnect;



Adapt the 7 variables ( on the 7 first lines ) then run the program


Références:



Links:

RPM packets for RHEL4 to install perl-DBD-Oracle with Oracle instant-client by Mathias Saou. (include also a patch to compile the oracle php module with the instant client)

Thanks to:

Pawel Grygiel for the update concerning the .zip archive that don't support symbolic links.


Jean-Christophe Duberga, jeanchristophe.duber >AT< free.fr - CRI - Université Bordeaux2