Skip to content

Instantly share code, notes, and snippets.

@jniltinho
Forked from rutcreate/README.md
Last active December 7, 2023 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jniltinho/3cc9a04243d8144609a963c295ba4483 to your computer and use it in GitHub Desktop.
Save jniltinho/3cc9a04243d8144609a963c295ba4483 to your computer and use it in GitHub Desktop.
Install Oracle InstantClient and SQL*Plus from source on Ubuntu 20.04

Download InstantClient

mkdir -p /opt/oracle
cd /opt/oracle
wget https://download.oracle.com/otn_software/linux/instantclient/218000/instantclient-basic-linux.x64-21.8.0.0.0dbru.zip
unzip instantclient-basic-linux.x64-21.8.0.0.0dbru.zip

Download SQLPlus

wget https://download.oracle.com/otn_software/linux/instantclient/218000/instantclient-sqlplus-linux.x64-21.8.0.0.0dbru.zip
unzip instantclient-sqlplus-linux.x64-21.8.0.0.0dbru.zip

After you unzip sqlplus package, you will see both lib files and sqlplus command inside directory instantclient_21_8

ls -la /opt/oracle/instantclient_21_8

Install Ubuntu dependency package

sudo apt install libaio1

Autoload LD_LIBRARY_PATH

sudo sh -c "echo /opt/oracle/instantclient_21_8 > /etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig

Add follow code to ~/.bashrc

export LD_LIBRARY_PATH=/opt/oracle/instantclient_21_8:$LD_LIBRARY_PATH
export PATH=/opt/oracle/instantclient_21_8:$PATH

Then logout and login again or run source ~/.bashrc to reload $PATH environment

Test connection

Use SQLPlus

sqlplus username:password@host:port/service_name

# password promt (better)
sqlplus username@host:port/service_name

Use Python

Install dependencies

pip install cx_Oracle

Connect to Oracle python script

import cx_Oracle as Database
user = 'username'
password = 'password'
dsn = Database.makedsn('host', 'port', service_name='service_name')
conn = Database.connect(user=user, password=password, dsn=dsn, encoding='UTF-8')

Django Database settings

Use service name

DATABASES = {
  'ENGINE': 'django.db.backends.oracle',
  'NAME': 'host:port/service_name',
  'USER': 'username',
  'PASSWORD': 'password',
}

Use SID

DATABASES = {
  'ENGINE': 'django.db.backends.oracle',
  'NAME': 'sid',
  'USER': 'username',
  'PASSWORD': 'password',
  'HOST': 'host',
  'PORT': 'port',
}

References

https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html#ic_x64_inst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment