Please note: this currently only applies to CentOS 7 and CentOS 8! See below for installations on Ubuntu 18.04, 20.04

Installing / Updating the oracle instant client

Packaging of oracle instant-client have been migrated to a separate repository to avoid version and dependency conflicts. To repository file /etc/yum.repos.d/oracle-instant.repo would look like this:

[oracle-instant]
name=DESY repository for oracle instant-client installs - $basearch
baseurl=http://nims.desy.de/extra/desy-asg/SL/7/$basearch/oracle-instant # ../8/.. for centos 8
enabled=0
gpgcheck=0

For automated updates the repository needs to be enabled.


oracle instant-client versions can not co-exist anymore, and installing a newer version requires prior removal of older versions:

# to install v19.6 and remove older packages you'd just need to include the config package, 
# which also contains pre-configured ora-files (sqlnet.ora, tnsnames.ora) and a module file
yum clean all --enablerepo=oracle-instant
yum install oracle-instantclient19.6-config --enablerepo=oracle-instant

# if you don't like installing the config-package for any reason, you'd need to clean up manually:
# remove oracle instant-client installations
yum remove oracle-instantclient\*

# install the packages needed for example
yum clean all --enablerepo=oracle-instant
yum install --enablerepo=oracle-instant oracle-instantclient19.6-tools \
            oracle-instantclient19.6-jdbc oracle-instantclient19.6-odbc oracle-instantclient19.6-devel

# for perl/python extension you'd need in either case:
# to install python3 and perl bindings. 
yum install --enablerepo=oracle-instant perl-DBD-Oracle python36-cx_Oracle

# to install deprecated python2 bindings. 
yum install --enablerepo=oracle-instant cx_Oracle


Configuring the Oracle Instant Client installation with puppet

puppet can automatically configure the repository and install a basic set of packages. To do so add to the hostgroups manifest something like

if $facts['os']['family'] == 'RedHat' and $facts['os']['release']['full'] == '7' {
  include oracleclient
}

This triggers the installation of the following packages:

	'oracle-instantclient19.6-config',
    'oracle-instantclient19.6-devel',
    'oracle-instantclient19.6-odbc',
    'oracle-instantclient19.6-sqlplus',
    'oracle-instantclient19.6-tools',
    'oracle-instantclient19.6-jdbc',
    'oracle-instantclient19.6-basic',
    'perl-DBD-Oracle',
    'python36-cx_Oracle',
    'sqldeveloper'

Be aware that the config-packages wipes (unavoidably) all previous versions and also includes the configuration files!


Using the oracle instant client

If the oracle-instantclient config package has been installed (see above) the environment can be initialized using the module command. Please note that /usr/local/bin/oraenv (if present) sets the environment for the full client, not the instant-client.

# using the module command. 
module load oracle-instant

# it's equivalent to the following
export PATH=/usr/lib/oracle/19.6/client64/bin:$PATH
export LD_LIBRARY_PATH=/usr/lib/oracle/19.6/client64/lib:$LD_LIBRARY_PATH
export FPATH=/usr/lib/oracle/19.6/client64/lib:$FPATH
export ORACLE_HOME=/usr/lib/oracle/19.6/client64
export ORACLE_SID=DESY
export TWO_TASK=desy_db.desy.de


Using the python extension

If the python-extension packages have been installed, the python modules are in the standard python search path and do not require any special setup. A simple example (test-oracle.py):

# replace username and database. get passwd interactively or via environment
import cx_Oracle
connection = cx_Oracle.connect("<username>", "<passwd>", "desy_db.desy.de", encoding="UTF-8")
cur = connection.cursor()
for row in cur.execute("select * from <database>"):
    print(row)
connection.close()
# environment
module purge
module load oracle-instant
# run
python3 test-oracle.py 

Using the perl extension

If the perl-extension package has been installed, the perl module is in the standard perl search path and does not require any special setup. A simple example (test-oracle.pl):

#!/usr/bin/perl -w
# largely taken from a perl-sample authored by K.Stock
use Getopt::Long;
use DBI;
use strict;

# Default values for options
my ( $trace, $inst, $cache, $delim, $format, $headers, $page_len, $null_str ) =
   ( 0, $ENV{TWO_TASK} || $ENV{ORACLE_SID} || '', '', "\t", 0, 0, 60, '' );

# set accordingly!
my $query = <query>;
my $user = <username>;
my $pass = <password>;

# Set trace level
DBI->trace( $trace );

# Connect to database
my $dbh = DBI->connect( "dbi:Oracle:$inst", $user, $pass,
    { AutoCommit => 0, RaiseError => 1, PrintError => 0 } )
    or die $DBI::errstr;
$dbh->{RowCacheSize} = $cache if $cache; # set fetch cache

# Start statement
my $sth = $dbh->prepare( $query );
$sth->execute;
my $nfields = $sth->{NUM_OF_FIELDS};

# print out any information which comes back
if ( $nfields ) {
    # the statement has output columns
    my ( @col, $col );
    my @name = @{$sth->{NAME}};
    if ( $format ) {
        # build format statements for the data
        my @size = @{$sth->{PRECISION}};

        # First, the header - a list of field names, formatted
        #    in columns of the appropriate width
        my $fmt  = join '|', map { "%-${_}.${_}s" } @size;
        $fmt     = sprintf $fmt, @name;
        $format = "format STDOUT_TOP =\n" . $fmt . "\n";

        # Then underlines for the field names
        $fmt    =~ tr/|/-/c;
        $fmt    =~ tr/|/+/;
        $format .= $fmt . "\n.\n";

        # Then for the data format, a @<<... field per column
        $fmt =~ tr/-+/<|/;
        $fmt =~ s/(^|\|)</$1@/g;
        $format .= "format STDOUT =\n" . $fmt . "\n";

        # Finally the variable associated with each column
        # Why doesn't Perl let us specify an array here?
        $format .= join ', ', map { "\$col[$_]" } 0 .. $#name;
        $format .= "\n.\n";

        eval($format);
    }
    elsif ( $headers ) {
        # Simple headers with underlines
        print map { s/\s+$//; $_ } @name;
        print map { tr//-/c;  $_ } @name;
    }

    # Associate @col with output columns and fetch the rows
    $sth->bind_columns( {}, \( @col[0 .. $#name] ) );
    while ( $sth->fetch ) {
        foreach $col ( @col ) { $col = $null_str if ! defined $col; }
        $format ? write : print @col;
    }
}

# finish off neatly
$sth->finish;
$dbh->disconnect;

__END__ 



# environment
module purge
module load oracle-instant
# run
perl test-oracle.py 


Installing / Updating the oracle full client

An AFS-hosted installation of the oracle full client is available. It allows concurrent installation of client versions. It is however only available on machines with AFS-connection. To use the full client, two packages (per version) needs to be installed:

# install the packages needed for example
yum install oracle.19.3-alias oracle.19.3-afs


Using the oracle full client

The environment can be set either using modules or oraenv/coraenv

# using the module command. 
module load oracle/19.3

# or alternatively 
. oraenv

# it's equivalent to the following
export PATH=/opt/oracle/19.3/bin:$PATH
export LD_LIBRARY_PATH=/opt/oracle/19.3/lib:$LD_LIBRARY_PATH
export FPATH=/opt/oracle/19.3/lib:$FPATH
export PYTHONPATH=/opt/oracle/19.3/python3.6/site-packages
export ORACLE_HOME=/opt/oracle/19.3
export ORACLE_SID=DESY
export TWO_TASK=desy_db.desy.de

Installing and using the oracle clients under Ubuntu

There are packages available for Ubuntu generated via alien. Please note: the full client has been tested for Ubuntu 18.04. Neither the instant-client nor the full client have been tested on other Ubuntu or Debian systems.

# instant client
# you don't need a special repository.Make sure to remove older instant client installations
# either use sudo or the package manager (green desktop)
sudo apt install oracle-instantclient19.6-config oracle-instantclient19.6-tools \
            oracle-instantclient19.6-jdbc oracle-instantclient19.6-odbc oracle-instantclient19.6-devel


# full client
sudo apt install oracle.19.3-afs oracle.19.3-alias

# make sure to have libaio1 installed. For the perl-binding you'd also need libaio-dev
sudo apt install libaio1 libaio-dev

# it's possible that the modules are not in your MODULEPATH. If you are getting an error loading the oracle module set
export MODULEPATH=/etc/modulefiles:$MODULEPATH

# to use the clients
module load oracle-instant # OR
module load oracle

Using the python extension

With the example (test-oracle.py) mentioned before, you could run

# environment
module purge
module load oracle/19.3
# run
python3 test-oracle.py 

This works without extensions installed, since the oracle installation comes with a separate cx_Oracle installation, but only for python3.6, as python2 has reached EOL.

Using the perl extension

# environment
module purge
module load oracle/19.3

# run the test
/opt/oracle/19.3/perl/bin/perl test-oracle.pl

The perl-extension come as part of the full client provided by oracle. The easiest is the use of Oracles perl-installation, which is however not in the PATH.

Installing Python and Perl extensions without packages

When no packages are available (e.g. Ubuntu), you can easily install the required components in your home-directory

# python
module load oracle/19.3 # or the instant client
pip3 install cx_Oracle --user
python3 test-oracle.py # should work now. 
# Note: Ubuntu 20.04 run python 3.8, all others 3.6. It hence will require pip installs for each of the different python versions. 

# perl
cpan DBI
cpan DBD:Oracle

# Note: when using cpan for the first time it might ask you to add perl-settings to your login script (e.g. ~/.bashrc). Either say yes or set it up yourself:
export PATH=$HOME/perl5/bin:$PATH
export PERL5LIB="$HOME/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"
export PERL_LOCAL_LIB_ROOT="$HOME/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"
export PERL_MB_OPT="--install_base \"$HOME/perl5\""
export PERL_MM_OPT="INSTALL_BASE=$HOME/perl5"

# run the test
perl test-oracle.pl # should work

Using sqldeveloper

Per default, sqldeveloper is installed together with the instant-client. sqldeveloper can use either the full or the instant client. The required JRE is not necessarily installed. Make sure, that you have a java runtime environment of your choice installed!

# environment for the full client
module purge
module load oracle/19.3 
# loading the module should be fully sufficient. Additionally/Alternatively load oraenv:
. oraenv  

# when starting sqldeveloper for the first time you might want to declare the location of the JRE. 
# Specifying something like /usr/lib/jvm/jre-11 sqldeveloper will store the location in ~/.sqldeveloper/<version>/product.conf
# The location stored in ~/.sqldeveloper/<version>/product.conf takes precedence. JAVA_HOME won't have any effect if it's already declared in product.conf
# Alternatively specify JAVA_HOME
. javaenv                                # tries to pick a suitable JRE. If that fails
export JAVA_HOME=/usr/lib/jvm/jre-11     # do it yourself
sqldeveloper

# environment for the instant client
module purge
module load oracle-instant
# loading the module should be fully sufficient. Additionally/Alternatively load oraenv:
. oraenv 
# 
. javaenv
sqldeveloper