How to setup Oracle Linux to use python to execute SQL commands on an ADW/ATP Instance in Oracle Cloud.
-
Download your cloud wallet zip files that contain your sqlnet.ora, tnsnames.ora and cwallet.sso files. These can be downloaded from the ATP/ADW instance from the web interface console.
-
Install https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html and download the oracle instant client. Pay attention to the version that you are downloading, as the environment needs to be setup with the correct paths. In this version I am using oracle instant client 19.3, if you are using a newer version or an older version make sure you change the instantclient_X_X to your needs.
-
sudo yum -y install oraclelinux-developer-release-el7
-
sudo yum -y install python-cx_Oracle
-
sudo mkdir -p /opt/oracle
-
sudo unzip /home/opc/instant_client.zip
-
sudo mv instantclient_19_3/ /opt/oracle/
-
cd /opt/oracle/instantclient_19_3/
-
sudo yum install libaio
-
sudo sh -c "echo /opt/oracle/instantclient_19_3 > /etc/ld.so.conf.d/oracle-instantclient.conf"
-
export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_3:$LD_LIBRARY_PATH
-
mkdir -p /opt/oracle/instantclient_19_3/network/admin
-
export TNS_ADMIN=/opt/oracle/instantclient_19_3/network/admin/
-
sudo ldconfig
-
sudo cp cwallet.sso /opt/oracle/instantclient_19_3/network/admin/
-
sudo cp tnsnames.ora /opt/oracle/instantclient_19_3/network/admin/
-
sudo cp sqlnet.ora /opt/oracle/instantclient_19_3/network/admin/
At this point you should have the python module installed. A test script to connect to your database is bellow:
#!/usr/bin/env python
import cx_Oracle
print('preconnection')
connection = cx_Oracle.connect('USERNAME', 'PASSWORD', 'SERVICE_NAME')
print('Connected')
cursor = connection.cursor()
cursor.execute('SELECT * from TEST')
print('Executed Select')
connection.close()