Satya's blog - Rails and Oracle

Feb 22 2010 20:16 Rails and Oracle

Getting Rails to work with Oracle is straight-forward. Get the instant client libraries from Oracle. I got the following, and unzipped them into /opt/oracle/instantclient-VERSION:

instantclient-basic-linux32-10.2.0.3-20061115.zip
instantclient-sdk-linux32-10.2.0.3-20061115.zip
instantclient-sqlplus-linux32-10.2.0.3-20061115.zip

for n in instantclient*.zip; do unzip $n; done

Symlink the directory so that we don't have to refer to it by version number, and then symlink certain files inside it because the libraries are supposed to be generically-named:

ln -s instantclient-VERSION instantclient
cd instantclient
ln -s libclntsh.so.11.1 libclntsh.so
ln -s libocci.so.11.1 libocci.so

In /etc/apache2/envvars add:

export LD_LIBRARY_PATH=/opt/oracle/instantclient:$LD_LIBRARY_PATH

And then install the ruby-oci8 driver, and the activerecord_oracle_adapter:

sudo env LD_LIBRARY_PATH=$LD_LIBRARY_PATH /usr/bin/gem install ruby-oci8 --version "< 2.0.0"
sudo gem install activerecord-oracle-adapter

Here's an example config/database.yml file:

production:
  adapter: oracle
  database: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=foo.example.com)(PORT=1234))(CONNECT_DATA=(SID=databse)))
  username: foo
  password: boo

There, all done. There might be a way to do this using ODBC but I'm just happy this works pain-free (unlike sybase).

Tag: rails