Saturday, May 19, 2012

Install & Configure Perl DBD for Oracle 11.2 on Redhat Linux


Steps 1: Install Oracle 11.2 server/client on the host

You can download oracle from download.oracle.com

Steps 2: Install Perl on the host.

Check if perl is already installed on the host:
# perl -v
Most hosts have perl already installed.
You can download and install perl from http://www.perl.org/get.html.

Step 3: Download PERL DBD-Oracle 


Download link: http://search.cpan.org/~pythian/DBD-Oracle-1.44/

Step 4: unzip and untar the download DBD-Oracle

[oracle@host1 tmp]$ gunzip DBD-Oracle-1.44.tar.gz
[oracle@host1 tmp]$ tar -xvf DBD-Oracle-1.44.tar

Step 5: Create file oci.conf 

Create file oci.conf at /etc/ld.so.conf.d/ as root with the location of Oracle LD_LIBRARY_PATH

For this example:
ORACLE_HOME=/u01/product/11.2
PATH=$PATH:$ORACLE_HOME/bin
LD_LIBRARY_PATH=/u01/product/11.2/lib

[root@host1 ~]$ more /etc/ld.so.conf.d/oci.conf
/u01/product/11.2/lib

Run ldconfig to update ld.so.conf

[root@host1 ld.so.conf.d]# ldconfig -v

What is ldconfig (from the man pages)
"DESCRIPTION: ldconfig  creates  the  necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib).  The cache is used by the run-time linker, ld.so or ld-linux.so.  ldconfig checks the header and filenames of the libraries it encounters when determining which versions should have their links updated."
For more details: http://linux.die.net/man/8/ldconfig

Step 6: Install DBD-Oracle

Go to the directory where u untared the downloaded DBD-Oracle
Note: Make sure u have completed Step 5

[root@host1 DBD-Oracle-1.44]# perl Makefile.PL -V 11.2.0
[root@host1 DBD-Oracle-1.44]# make install

This should complete the DBD-Oracle installation!!!!!

Step 7: Test the install

Login back as Oracle user:
Create a script (dbd_oracle_test.pl) with the text below:


#!/usr/bin/perl


$host="host1";
$ora_listener="LISTENER";
$oracle_sid="test";
$listener_port="1521";
$ora_user="system";
$ora_password="oracle";
$db_table="dba_users";


use DBI;
use DBD::Oracle;


my $dbh = DBI->connect("dbi:Oracle:host=$host;port=$listener_port;sid=$oracle_sid",$ora_user, $ora_password)
  or die "Error Connecting to Oracle : " . DBI->errstr;


my $stm = $dbh->prepare("SELECT username,created FROM $db_table")
  or die "Database Error: " . $dbh->errstr;


$stm->execute()
  or die "Database Error: " . $sth->errstr;


while (( $username,$created ) = $stm->fetchrow_array() )
{
print "\n";
print " Username: $username\n";
print " Created Date: $created\n";
print "\n";
}


$stm->finish;


$dbh->disconnect;

4 Comments:

xxx said...

Hey, thank you for putting this together! It helped me a lot to install my dev environment with Perl and Oracle in RHEL6!

Jhmnieuwenhuis said...

Excellent guide!!

Jhmnieuwenhuis said...

Very good guide, thanks!!

Anonymous said...

thank for great toturial :)