Thursday, September 6, 2007

RoR, Oracle, sqlplus and life

Update: Read this if you want to use Oracle 10g Express edition on Linux 64 bit White box


This took me some time to find, so I will document it for everyone's benefit.

At work, I needed to use an Oracle database for my RoR apps.

Here is a quick summary of steps to install the Ruby oci driver etc:

  1. First download Oracle Instantclient and install it to say /opt/oracle/10.2.0.3
    This makes connecting to Oracle a snap. Very useful indeed.


  2. setenv LD_LIBRARY_PATH /opt/oracle/10.2.0.3
    setenv ORACLE_HOME /opt/oracle/10.2.0.3
    setenv NLS_LANG AMERICAN_AMERICA.UTF8

    # install oci driver
    wget http://rubyforge.org/frs/download.php/22320/ruby-oci8-1.0.0-rc3.tar.gz
    tar xvzf ruby-oci8-1.0.0-rc3.tar.gz
    cd ruby-oci8-1.0.0-rc3
    ruby setup.rb config -- --with-instant-client=/opt/oracle/10.2.0.3
    make
    make install

  3. test it


    %> irb
    irb(main):001:0> require 'oci8'
    => true
    irb(main):002:0> exit

  4. Specify the following in your database.yml
    production:
    adapter: oci
    host: //dbHost:1521/oracle_instance
    username: xxxx
    password: xxxx

  5. To use sqlplus to connect to the Oracle db

    sqlplus username/password@//dbHost/Oracle_db_instance

    or (if you don't want the pwd to be visible in ps listings)

    sqlplus /NOLOG
    SQL*Plus: Release 10.2.0.3.0 - Production on Thu Sep 6 17:08:28 2007

    Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

    SQL> connect username/password@//dbHost/Oracle_db_instance

    No need to muck with any tnsnames.ora.


No comments: