Nathan's Blog computer stuff

October 31, 2008

Installing DBD::Oracle on Mac OS X Leopard , Native Intel

Filed under: oracle,perl — nathan @ 4:24 pm

Install Perl DBD::Oracle natively on intel mac

There are two options for this:

  • Use the built in perl in /usr, patch DBD::Oracle
  • Use the perl from macports, use stock DBD::Oracle

Prerequesites:

  • This is tested on Leopard on an Intel mac.
  • These examples assume the bash shell, though it would probably work with ksh as well.
  • You must have Xcode installed.
  • For the MacPorts perl, you must have MacPorts installed and working. For instructions on installing macports, go here.

If you want to skip down to configuring the built in perl for DBD::Oracle, click here.
If you would like to skip down to installing / configuring DBD::Oracle for Macports perl, click here

Installing the Instant Client

Now that Oracle has released the 10.2.0.4 instant client for Intel Mac, it is now possible to use DBD::Oracle without having to run perl under Rosetta as before.

For both methods, we’ll need to first install the instant client. I have a specific way of doing it which works for me. This is certainly not the only way to accomplish a working setup, but the rest of this blog assumes installation is done exactly this way.

Download the Instant client

http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/intel_macsoft.html

  • instantclient-basic-macosx-10.2.0.4.0.zip
  • instantclient-sqlplus-macosx-10.2.0.4.0.zip
  • instantclient-sdk-macosx-10.2.0.4.0.zip

unzip them. If you want to do this from the cli, cd into the directory where you downloaded them. For instance:

(nathan@smac:~)$ cd Downloads
(nathan@smac:~/Downloads)$ find . -name "instantclient-*10.2.0.4.0.zip" -exec unzip {} \;

cd into the instantclient_10_2 directory.

(nathan@smac:~/Downloads)$ cd instantclient_10_2/
(nathan@smac:~/Downloads/instantclient_10_2)$

Now we need to create some directories:

(nathan@smac:~/Downloads/instantclient_10_2)$ mkdir bin
(nathan@smac:~/Downloads/instantclient_10_2)$ mkdir lib
(nathan@smac:~/Downloads/instantclient_10_2)$ mkdir -p network/admin

Now we need to move some files into appropriate directories:

(nathan@smac:~/Downloads/instantclient_10_2)$ mv *.dylib* *.jar *.jnilib lib/
(nathan@smac:~/Downloads/instantclient_10_2)$ mv sqlplus genezi bin/

Now we need to make some symlinks in the lib directory:

(nathan@smac:~/Downloads/instantclient_10_2)$ cd lib
(nathan@smac:~/Downloads/instantclient_10_2/lib)$ ln -s libclntsh.dylib.10.1 libclntsh.dylib
(nathan@smac:~/Downloads/instantclient_10_2/lib)$ ln -s libocci.dylib.10.1 libocci.dylib

These are useful because the DBD::Oracle Makefile will not find these dylib’s unless these symlinks are in place, regardless of DYLD_LIBRARY_PATH . I imagine that other programs might expect these symlinks as well.

This next step isn’t at all necessary, but if you want to use their glogin.sql:

(nathan@smac:~/Downloads/instantclient_10_2)$ mkdir -p sqlplus/admin
(nathan@smac:~/Downloads/instantclient_10_2)$ mv glogin.sql sqlplus/admin

Now you need to move the instant client directory that we just prepared to some final resting place. You can either leave it in your home directory or you could put it into a system-wide location. for this example, I’m going to use /opt/oracle/instantclient_10_2

(nathan@smac:~/Downloads/instantclient_10_2)$ cd ..
(nathan@smac:~/Downloads)$ sudo mkdir -p /opt/oracle
Password:
(nathan@smac:~/Downloads)$ sudo mv instantclient_10_2 /opt/oracle/

Set some environment variables. For instance:

export ORACLE_HOME=/opt/oracle/instantclient_10_2
export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$PATH:$ORACLE_HOME/bin

You need to copy a working tnsnames.ora file into your $ORACLE_HOME/network/admin location. For instance:

cp /path/to/tnsnames.ora $ORACLE_HOME/network/admin/

Now you should test your installation.
test sqlplus:

sqlplus user/pass@connection_id

Once you have this working, you will probably want to set those environment variables in your login profile. To do this you could:

echo "
export ORACLE_HOME=/opt/oracle/instantclient_10_2
export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$PATH:$ORACLE_HOME/bin" >> ~/.profile

Or any other way you see fit to do it.

Installing for built-in perl

First, su to root.

(nathan@smac:~)$ sudo su -
Password:
(root@smac:~)#

Verify that the correct perl shows up first on the command line:

(root@smac:~)# which perl
/usr/bin/perl
(root@smac:~)#

This is the correct perl. If you see /opt/local/bin/perl instead, you need to set the PATH variable to where /usr/bin comes before /opt/local/bin

now type the following:

(root@smac:~)# perl -MCPAN -e shell

It will likely ask you a lot of questions. Generally you should be fine with the defaults. Dont’ worry if it can’t find certain programs like lynx, ncftp, gpg . You can install them from macports if you would prefer, then restart the CPAN shell with the command above. Or continue without it. It will also ask you to select a mirror appropriate for your location, then finally you will get to a cpan prompt that looks like:

cpan>

(optional) You may want to install Bundle::CPAN at this point. Probably a good idea. To do so, type:

cpan> install Bundle::CPAN

It will go through a long process, will ask you several times if you want to prepend dependencies on to the queue. Again, you can just keep hitting enter to go with the defaults, which should be sane.

Once that’s done, type the following:

cpan> install DBI
cpan> exit

Now we need to download DBD::Oracle manually and patch it. Wee!

You can do the following:

grab this: http://search.cpan.org/CPAN/authors/id/P/PY/PYTHIAN/DBD-Oracle-1.22.tar.gz

Un-tar it and cd into the directory. For this, you will want to start up a new terminal window which will be logged in as your userid. Do something like thefollowing:

(nathan@smac:~/Downloads)$ tar xzvf DBD-Oracle-1.22.tar.gz
(nathan@smac:~/Downloads)$ cd DBD-Oracle-1.22
(nathan@smac:~/Downloads/DBD-Oracle-1.22)$

Now download the following patch:

http://nathanjohnson.info/dbdimp.diff

and save it into the folder that you just cd’ed into (in this case, ~/Downloads/DBD-Oracle-1.22)

(note: the idea for this patch came from this thread: http://www.macosxhints.com/article.php?story=20061021211559813 – my patch is not the one listed in these forums, but instead fixes the problem with the function rather than deleting references to it. I have since posted this patch to the cpan bug tracking page for DBD::Oracle on ticket #21920.)

EDIT: According to this, this has patch has been merged with the trunk of DBD::Oracle, so it may well be that with the next release this package (1.23?) the patch will no longer be necessary

Apply the patch:

(nathan@smac:~/Downloads/DBD-Oracle-1.22)$ patch < dbdimp.diff
patching file dbdimp.c
(nathan@smac:~/Downloads/DBD-Oracle-1.22)$

Now we need to set a couple more environment variables. Note, these next steps require a working connection to an oracle database, a tnsnames.ora file that lives in $ORACLE_HOME/network/admin , and a valid connection specifier , username and password. These actions will be done in the shell window that is logged in as root:

Now we need to set some environment variables:

(root@smac:~)# export ORACLE_HOME=/opt/oracle/instantclient_10_2
(root@smac:~)# export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib
(root@smac:~)# export TWO_TASK=connection_specifier
(root@smac:~)# export ORACLE_USERID=username/password

Now we need to cd to the directory where we downloaded DBD-Oracle. In my example, it would be /Users/nathan/Downloads/DBD-Oracle-1.22 .

(root@smac:~)# cd /Users/nathan/Downloads/DBD-Oracle-1.22/
(root@smac:/Users/nathan/Downloads/DBD-Oracle-1.22)#

Now, issue the following:

perl Makefile.PL -l

This -l is important, if you omit it, it will fail.

then issue:

make

then:

make test

I received two failures in the select test, I’m not sure why but these don’t seem to be show stoppers. If you get other errors, the following reasons could be the culprit:

  1. TWO_TASK is not set to a valid entry in tnsnames.ora
  2. ORACLE_HOME is not set to the oracle install location
  3. DYLD_LIBRARY_PATH is not set to the $ORACLE_HOME/lib directory
  4. missing or invalid ORACLE_USERID variable

Once you’re satisfied with the results of make test, issue:

make install

DBD::Oracle is installed!

Macports Perl

For option 2, you must have MacPorts installed and working. For instructions on installing macports, go here.

It is assumed that /opt/local/bin and /opt/local/sbin will be in your path , and in this example they should be in your path before /usr/bin and /usr/local/bin (more on this below).

Now we need to install the macports version of perl. I have tested with version 5.8. 5.10 would probably work as well.

sudo port install perl5.8

Go get coffee.

Once perl is installed, you will want to start with CPAN.

su to root:

(nathan@smac:~)$ sudo su -
Password:
(root@smac:~)#

Now we need to set some environment variables:

(root@smac:~)# export ORACLE_HOME=/opt/oracle/instantclient_10_2
(root@smac:~)# export DYLD_LIBRARY_PATH=$ORACLE_HOME/lib
(root@smac:~)# export PATH=/opt/local/bin:/opt/local/sbin:$PATH:$ORACLE_HOME/bin

Verify that the macports perl shows up first on the command line:

(root@smac:~)# which perl
/opt/local/bin/perl
(root@smac:~)#

This is the correct perl. If you see /usr/bin/perl instead, you need to set the PATH variable as above.

now type the following:

(root@smac:~)# perl -MCPAN -e shell

It will likely ask you a lot of questions. Generally you should be fine with the defaults. Dont’ worry if it can’t find certain programs like lynx, ncftp, gpg . You can install them from macports if you would prefer, then restart the CPAN shell with the command above. Or continue without it. It will also ask you to select a mirror appropriate for your location, then finally you will get to a cpan prompt that looks like:

cpan>

(optional) You may want to install Bundle::CPAN at this point. Probably a good idea. To do so, type:

cpan> install Bundle::CPAN

It will go through a long process, will ask you several times if you want to prepend dependencies on to the queue. Again, you can just keep hitting enter to go with the defaults, which should be sane.

Once that’s done, type the following:

cpan> install DBI

And then, finally:

cpan> install DBD::Oracle

This will fail. I only mention attempting here so that cpan will do the work of fetching it and extracting it to the build directory.

Exit CPAN by typing the following:

cpan> exit

Type the following:

cd ~/.cpan/build/DBD-Ora

and then hit tab . It should complete to wherever it downloaded the DBD::Oracle to, which on my system at the time of this writing was DBD-Oracle-1.22

Now we need to set a couple more environment variables. Note, these next steps require a working connection to an oracle database, a tnsnames.ora file that lives in $ORACLE_HOME/network/admin , and a valid connection specifier , username and password

export TWO_TASK=connection_specifier
export ORACLE_USERID=username/password

Now we need to run the following command:

perl Makefile.PL -l

This -l is important, if you omit it, it will fail.

then issue:

make

then:

make test

If make test fails, that may be because of any of the following:

  1. TWO_TASK is not set to a valid entry in tnsnames.ora
  2. ORACLE_HOME is not set to the oracle install location
  3. DYLD_LIBRARY_PATH is not set to the $ORACLE_HOME/lib directory
  4. missing or invalid ORACLE_USERID variable

Once make test returns cleanly, you can finally do:

make install

This will install DBD::Oracle for the /opt/local installation of Perl.

Older Posts »

Powered by WordPress