I am establishing a connection to oracle 11g which is in a remote server using cx_oracle 7 with python 3.6.7. my OS in Ubuntu 18.04
I have installed oracle instant c
If you're working with aws lambdas to connect to your RDS/OracleDB, then try this approach using Docker to automated the build for the aws lambda layer - https://medium.com/@sabithvm/building-up-on-lambda-layers-a4771d3b9c7
After some more research i got the solution from ubunu community , after you have installed oracle instantclient you will have to integrate oracle libraries as follows:
export LD_LIBRARY_PATH=/usr/lib/oracle/
<version>
/client(64)/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}For example, 12.1 version for Linux x86_64:
export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
where <version>
indicates the version of your of your oracle intantclient e.g 11.2, 12.2
The connection parameter should be as follows connection = cx_Oracle.connect("username/password@host/service_name e.g orcl")
to get the listener/service_name type the following in the oracle sqlplus
SQL> show parameter local_listener
the value is the listener
For Ubuntu Linux 20.04 LTS server what worked for me (which may be obvious but wasn't to me!) is 1) when you perform the export, you need to be in the folder you intend to run the app/ command connecting to Oracle from, and although this worked, after closing the SSH terminal to the EC2 server, was then not available again which was resolved by 2) Add it to ~/.bashrc Steps in full:
With the Oracle instant client unzipped in for example: /opt/oracle/instantclient_19_9
sudo apt-get install libaio1
cd ~/your-project-folder
export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_9
I then added to ~/.bashrc with:
sudo nano ~/.bashrc
And add this line:
export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_9
And in the terminal run:
source ~/.bashrc
Mine worked as expected installed on an EC2 server under 'ubuntu' user with requisite nvm/ nodeJs installed
In nodeJs an example connection might look something like:
const testOracleConnection = async () => {
let conn;
try {
conn = await oracledb.getConnection(oracleConfig);
const query1 = 'select ID, anotherColumn from someTable where ID = 1111';
const result = await conn.execute(query1);
console.log(result);
} catch (err) {
console.error(err);
} finally {
if (conn) {
try {
await conn.close();
} catch (err) {
console.error(err);
}
}
}
};
I was facing the exact same problem. This is what worked for me:
$ sudo mkdir -p /opt/oracle
$ cd /opt/oracle
$ sudo unzip /opt/oracle/instantclient-basic-linux.x64-19.8.0.0.0dbru.zip
$ sudo apt-get install libaio1
LD_LIBRARY_PATH
$ vim ~/.bashrc
.bashrc
file export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_8:$LD_LIBRARY_PATH
.bashrc
file, I sourced it: $ source ~/.bashrc
Then my Python script worked nicely again.
See also the cx_oracle documentation