I've followed the official installation guide but haven't had any luck so far. I wonder if cx_Oracle can work on AWS SageMaker's virtual environment. The steps I've used so far are:
Create a /opt/oracle directory and unzip the basic instantclient in it.
sudo yum install libaio
sudo sh -c "echo /opt/oracle/instantclient_18_3 > /etc/ld.so.conf.d/oracle-instantclient.conf" and
sudo ldconfig
And finally exported the LD_LIBRARY_PATH with: export LD_LIBRARY_PATH=/opt/oracle/instantclient_18_3:$LD_LIBRARY_PATH
When trying to run a connection inside the notebook with connection = cx_Oracle.connect(usr + '/' + pwd + '#' + url), I receive the DPI-1047 error code that says that libclntsh.so cannot be open, however that library is in the /opt/oracle folder. As another option, when running the same connection through the terminal Python console, I get the ORA-01804 error code, which says that the timezone files were not properly read, which is something I'm trying to fix also but suspect is related to cx_Oracle not finding its library folder. (Now, explain to me: why does it have to be so difficult for a billionaire company to create a decent library import and installation?)
Is there a step I'm missing? Is there a detail about AWS SageMaker that I should account for? Also, is there another option for extracting data from an oracle server through Python and AWS?
Hi and thank you for using SageMaker!
After some effort, I was finally able to figure out a sequence of steps that allowed me to query an Oracle 12 database from within a SageMaker notebook instance. Here are the steps that I took:
I created an Oracle 12 database using Amazon RDS for testing purposes. (You can of course skip this step if you already have an Oracle database available.)
I downloaded the Oracle 12 Instant Client RPM as described here. Note that you will need an Oracle Account in order to download this file.
I uploaded the RPM to my SageMaker Notebook Instance from within JupyterLab. Note that this can take 2-3 minutes to completely upload before proceeding to the next step. (I initially had problems running the installation because the upload was still in progress.)
I ran all of the following commands from the Jupyter terminal as prescribed in the Oracle instructions:
cd SageMaker
sudo yum install oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
sudo sh -c "echo /usr/lib/oracle/12.2/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig
sudo mkdir -p /usr/lib/oracle/12.2/client64/lib/network/admin
# Restart Jupyter...
sudo restart jupyter-server
I then installed the cx_Oracle library:
source activate python3
pip install cx_Oracle --upgrade
Then lastly, I created a new notebook using the conda_python3 kernel:
import cx_Oracle
db = cx_Oracle.connect("my_username/my_password#my-rds-instance.ccccccccccc.us-east-1.rds.amazonaws.com/ORCL")
# Example query
cursor = db.cursor()
for row in cursor.execute('select * from DBA_TABLES'):
print(row)
...and then it worked!
Note that it took me a few tries to figure out the exact connection string, which can differ depending on how your database is configured. Unfortunately, the error messages were hard to understand - in my case, I had the error ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA until I had specified the /ORCL at the end of the connection string.
If you need to do these steps frequently, you can add the installation and configuration of the Oracle client in a SageMaker Lifecycle Configuration script. I haven't tested that scenario, but it might be worth a try!
One last thing, I noticed in your question that you are using the Oracle 18 client. I didn't test that exact scenario, since I only have access to an Oracle 12 database. However, the Oracle 12 client should be able to connect to an Oracle 18 database, too.
Best,
Kevin
Related
I have a requirement in which I need to connect to oracle database and get some data from db table. So as I am a beginner in aws lambda so i started with below example.
import cx_Oracle
import os
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def lambda_handler(event, context):
logger.info('begin lambda_handler')
dsn = cx_Oracle.makedsn("hostname", "1521", "sid")
con = cx_Oracle.connect("user_id", "password", dsn)
cur = con.cursor()
#logger.info('username: ' + username)
#logger.info('host: ' + host)
sql = """SELECT COUNT(*) AS TEST_COUNT FROM DUAL"""
cur.execute(sql)
columns = [i[0] for i in cur.description]
rows = [dict(zip(columns, row)) for row in cur]
logger.info(rows)
con.close()
logger.info('end lambda_handler')
return "Successfully connected to oracle."
I created below structure in linux for creating deployment package.
Parent_Directory
-lib(Under this library i placed all the oracle instant client files)
-cx_oracle files
lmbda_function.py
after deploying the package on aws lambda and testing it, I get below error.
[ERROR] DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "/var/task/lib/libclntsh.so: file too short". See https://oracle.github.io/odpi/doc/installation.html#linux for help
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 29, in lambda_handler
Please somebody help me to achieve this, also if there is any better option to connect with oracle from aws lambda than please share.
I was running into the same problem. After reading this article it looks like you are missing the libaio.so.1 file. I am guessing you downloaded the instant client from a windows machine because from what I understand, the libaio file is not included when downloading onto the windows platform. I was able to download the libaio.so.1 file from this repo. Just make sure to put it in the lib folder with the other oracle instant client files.
Snip up an Ec2 instance
Download cx_Oracle-7.3.0-cp37-cp37m-manylinux1_x86_64.whl - https://pypi.org/project/cx-Oracle/#files
Download Oracle instant client - https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html (instantclient-basiclite-linux.x64-21.3.0.0.0)
Download lib64aio1-0.3.111-1pclos2018.x86_64.rpm
In Ec2 instance, please follow below steps
sudo yum update
Install pip ( sudo yum install python3-pip) – If pip is not installed. I think by default we will get pip in Ec2. You can check the version by running command “pip3 –version”
The next step is to install Pipenv. A virtual environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them.
sudo pip3 install virtualenv
Virtualenv oraclelambda(some folder name), you will see a directory with name oraclelambda
source oraclelambda/bin/activate
Pip install cx_Oracle-7.3.0-cp37-cp37m-manylinux1_x86_64.whl (You will notice cx_Oracle installed in oraclelambda directory)
sudo yum remove libaio-0.3.109-13.amzn2.0.2.x86_64
sudo yum install lib64aio1-0.3.111-1pclos2018.x86_64.rpm
Next go to usr/lib64 – you will see libaio.so.1.0.1 (copy this file)
Next step extract oracle instant client
Paste the libaio.so.1.0.1 file into instant client folder and rename the libaio.so.1.0.1 file to libaio.so.1
Next step is grab that instant client folder for instance it would be instantclient_21_3 out from the extracted zip and zip it
Create new folder with name python and create the another lib folder inside the python folder.
Next step is copy the python3.7 folder from oraclelambda/lib64 and place it in phthon/lib folder. The folder structure would be python\lib\python3.7\site-packages\
Now zip the python folder
At this point we have two zip files
Instantclient
Python
The above two zip files we are going to update them in lambda layers
Create the lambda, update the zip files into the layers, have proper security groups created.
Please add below to lambda’s environment variables so that it can locate the Oracle Instant Client library.
Key = LD_LIBRARY_PATH
Value = /opt/
I was having a similar issue. It was resolved after I downloaded the Oracle Client library & libaio and bundled it with cx_Oracle while creating a Lambda Layer. You may follow the below video I created for this activity. Hope it is helpful to you - https://www.youtube.com/watch?v=BYiueNog-TI&ab_channel=BorrowedCloud
So I'm going to preface this by saying that I CANNOT use sudo apt-get install sqlite3. I am doing this project in a VM on google cloud platform, and our VMs are not allowed to have external IP access because we have sensitive information on these VMs. So running that command just hangs.
I went to the sqlite website and downloaded the Precompiled Binaries for Linux and put that on google cloud storage (gcs). I am able to cp the directory from gcs to the VM, but
ultimately, I cannot figure out a way to get it to run. When I cd to the directory, I see there are 3 objects sqldiff, sqlite3, sqlite3_analyzer, of which Im including an image in case you want to reference it.
I was testing out an idea at home, where I have a pc that can dual boot linux, and I was able to run sqlite3 just find from the command when I did a sudo apt-get for it (i.e. I get
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
), but I'm having problems here. I can't seem to do anything after this within the VM I am trying to run the actual code in now. I am pretty inexperienced with ubuntu and linux systems, so maybe I'm just missing something easy.
Thank you to anyone who can offer some advice.
Have you tried building the binaries from source?
https://www.sqlite.org/howtocompile.html
This worked for me when I downloaded the source code amalgamation.
Ideally, gcc should be present on your VM
$ : gcc shell.c sqlite3.c -lpthread -ldl -o sqlite3_cli
$ : ./sqlite3_cli
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>
With the help of cx_Oracle package I am trying to connect to remote Oracle database. Unfortunately I have error when try to test next python code:
import cx_Oracle;
dsn_tns=cx_Oracle.makedsn('HOST', 'PORT', service_name='NAME')
connection=cx_Oracle.connect('USERNAME', 'PASSWORD', dsn_tns)
ERROR:
cx_Oracle.Database: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Dependencies:
1) Ubuntu 14.04 (64 bit) (local computer)
2) Python 2.7.14 (64 bit)
3) cx_Oracle 6.4.1
4) Instant Client 18.3
5) Oracle 11g database (located in remote server)
I used official documentation to install and configurate instant client.
Official documentation say that:
Oracle Call Interface 18.3 can connect to Oracle Database 11.2 or
later.
For thats why I load basic package of instant client 18.3, then unzip it:
cd /opt/oracle
unzip instantclient-basic-linux.x64-18.3.0.0.0dbru.zip
Then I install libaio:
sudo apt-get install libaio1
In terminal I wrote next 2 command:
sudo sh -c "echo /opt/oracle/instantclient_18_3 > /etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig
Inside /opt/oracle/instantclient_18_3/network/admin I put tnsnames.ora file.
After that I set environment variable in ~/.profile:
export LD_LIBRARY_PATH=/opt/oracle/instantclient_18_3:$LD_LIBRARY_PATH
export TNS_ADMIN=/opt/oracle/instantclient_18_3/network/admin
export PATH=/opt/oracle/instantclient_18_3:$PATH
What else should I have done to fix the problem?
What's wrong with instant client? Absolutely nothing from the information you supplied. You are connecting to the server (listener) but the server is not configured with the database you specified.
You can confirm this with a different client / different client host.
Go check the config on the server.
ok, so I have researched the other topics on this, but I still can't get this thing to work, and I'm sure its something small I'm overlooking.
I have my python script running on my local host as a web service.
I have my postgresql instance running on my local host with a specific port, and a database created with a table that has data.
All I want to do is utilize psycopg2 to connect to my database from the python script. Should be pretty simple.
Now, as I understand it, I should be able to just download the psycopg2 file, run the setup, and move on from there.
Could someone PLEASE point me in the direction of how to do this? The python setup.py build and/or install command results in permission denied, which is just odd. I ran it with sudo, and again, same thing.
This is the last piece I need to get in place before I can continue working on the application that I was working on.
Have you tried using pip?
pip search psycopg2
if not installed
pip install psycopg2
I am trying to install mongodb on my production instance, following this tutorial.
Everything seems to be fine, im seeing mongo on info.php and the sample connection is working.
But, when i run mongod or service mongod start from command line
i get mongod: unrecognized
service
Also when i run sudo find / -type f -name *mongo* this is what i get.
/home/userName/.npm/mongodb/1.1.3/package/lib/mongodb/responses/mongo_reply.js
/home/userName/.npm/mongodb/1.1.3/package/lib/mongodb/connection/mongos.js
/usr/lib64/php/modules/mongo.so
/usr/share/pear/.registry/.channel.pecl.php.net/mongo.reg
/usr/share/vim/vim72/keymap/mongolian_utf-8.vim
question what am i missing?
Up until now i have been testing locally on a windows machine.
You need to install the database package itself (you have so far installed all the libraries to connect to it, but not the database). Follow the instructions here:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-redhat-centos-or-fedora-linux/
And you will have the appropriate service as needed.