Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Environment variable woes connecting to Oracle

by seawarrior (Initiate)
on Apr 11, 2017 at 18:12 UTC ( [id://1187678]=perlquestion: print w/replies, xml ) Need Help??

seawarrior has asked for the wisdom of the Perl Monks concerning the following question:

Given this test program that connects to Oracle:

#!/usr/bin/perl -I/home/install/perl $ENV{'ORACLE_HOME'}="/home/root/home/xyzco/oracle/oracle/product/12.1. +0/dbHome_1"; $ENV{'LD_LIBRARY_PATH'}="/home/root/home/xyzco/oracle/oracle/product/1 +2.1.0/dbHome_1/lib:/lib:/usr/lib"; use DBI; print $ENV{'LD_LIBRARY_PATH'}; $dbh = DBI->connect( "dbi:Oracle:host=127.0.0.1;sid=V1011679;port=1521 +", isx, devpassXD0kei4Eo3W3n9n, { AutoCommit => 1} );

The output is as follows; i.e. it fails to connect complaining that it can't load /home/install/perl/auto/DBD/Oracle/Oracle.so.

site1:/home/install/perl/auto/DBD/Oracle # perl test.pl AJS Dynaloader -/home/install/perl/auto/DBI/DBI.so- AJS Dynaloader AJS Dynaloader -/home/install/perl/auto/DBD/Oracle/Oracle.so- /home/root/home/xyzco/oracle/oracle/product/12.1.0/dbHome_1/lib:/lib:/ +usr/libAJS Dynaloader /home/root/home/xyzco/oracle/oracle/product/12. +1.0/dbHome_1/lib:/lib:/usr/lib install_driver(Oracle) failed: Can't load '/home/install/perl/auto/DBD +/Oracle/Oracle.so' for module DBD::Oracle: libclntsh.so.11.1: cannot +open shared object file: No such file or directory at /usr/lib/perl5/ +5.10.0/x86_64-linux-thread-multi/DynaLoader.pm line 205. at (eval 3) line 3 Compilation failed in require at (eval 3) line 3. Perhaps a required shared library or dll isn't installed where expecte +d at test.pl line 7

HOWEVER, if I explicitly define the environment variable in the shell:

site1:/home/install/perl/auto/DBD/Oracle # declare -x LD_LIBRARY_PATH= +"/home/root/home/xyzco/oracle/oracle/product/12.1.0/dbHome_1/lib:/lib +:/usr/lib"

and then run the program:

site1:/home/install/perl/auto/DBD/Oracle # perl test.pl AJS Dynaloader -/home/install/perl/auto/DBI/DBI.so- AJS Dynaloader /home/root/home/xyzco/oracle/oracle/product/12.1.0/dbHo +me_1/lib:/lib:/usr/lib AJS Dynaloader -/home/install/perl/auto/DBD/Oracle/Oracle.so- /home/root/home/xyzco/oracle/oracle/product/12.1.0/dbHome_1/lib:/lib:/ +usr/libAJS Dynaloader /home/root/home/xyzco/oracle/oracle/product/12. +1.0/dbHome_1/lib:/lib:/usr/lib

...then it is successful. Why doesn't the program work when I define the environment variable from inside the program but not in the shell? OS is SLES11. Thanks for your help!

Replies are listed 'Best First'.
Re: Environment variable woes connecting to Oracle
by stevieb (Canon) on Apr 11, 2017 at 18:39 UTC

    LD_LIBRARY_PATH *must* be set before perl is loaded. You can either set it at the command line prior to running your script, or wrap your perl script with a shell script where you can set the env var, then kick off the perl script.

      LD_LIBRARY_PATH *must* be set before perl is loaded.

      Generally, yes, but for loading the propritary DLLs required by DBD::Oracle, no. It is sufficient to set up the environment variables before DBD::Oracle is loaded.

      This should also work:

      #!/usr/bin/perl use lib '/home/install/perl'; BEGIN { # Setup Environment for Oracle - has to happen *before* DBD::Oracl +e is loaded, # and because DBI loads DBD::Oracle during its startup, this has t +o happen # before the first "use DBI". $ENV{'ORACLE_HOME'}="/home/root/home/xyzco/oracle/oracle/product/1 +2.1.0/dbHome_1"; $ENV{'LD_LIBRARY_PATH'}="/home/root/home/xyzco/oracle/oracle/produ +ct/12.1.0/dbHome_1/lib:/lib:/usr/lib"; } use DBI; print $ENV{'LD_LIBRARY_PATH'}; $dbh = DBI->connect("dbi:Oracle:host=127.0.0.1;sid=V1011679;port=1521" +, "user", "password", { AutoCommit => 1});

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        That's great! Thanks for digging deeper on the issue.

      Thank you sir.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1187678]
Approved by haukex
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-26 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found