Downloadthe desired Oracle Instant Client RPM packages. Select the correct platform, architecture, and packages of your choice. For example, if your application is 64-bit, then ensure that you select 64-bit Instant Client and download the Basic Package RPM file.
If you intend to colocate optional Oracle configuration files such as tnsnames.ora, sqlnet.ora, ldap.ora, or oraaccess.xml with Oracle Instant Client, then move these files to the /usr/lib/oracle/21/client64/lib/network/admin subdirectory.
The Oracle Instant Client is a light-weight, freely distributable implementation of an Oracle client. A big advantage of the Instant Client is it does not need a formal installation. Instead, it can be unzipped and used without any fuss.
Since September 2018 the instant client RPMs have been freely available on
yum.oracle.com. If you are using Oracle Linux and have root access you can install the instant client using Yum with a few simple commands.
There are a number of downloads available, depending on which features you require. The Linux versions also come with an RPM option, but as this requires root privilege to install, it may not be considered so desirable. The basic download provides all the core functionality necessary to make basic connections from Java. In this case, I wanted to make SQL*Plus connections, so I downloaded the following zip files.
When using the Instant Client, we need to make sure the LD_LIBRARY_PATH environment variable is set to point to the location where the software was unzipped. In this case, I also set the PATH environment variable.
If you would prefer to use a "tnsnames.ora" file, you can do that too. Just set the TNS_ADMIN environment variable to the directory holding the file and it will work as expected. For example, imagine I had a "tnsnames.ora" file in my home directory with the following contents.
The cx_Oracle module loads Oracle Client libraries which communicateover Oracle Net to an existing database. Oracle Net is not a separateproduct: it is how the Oracle Client and Oracle Database communicate.
Add Oracle 21, 19, 18, 12 or 11.2 client libraries to your operating systemlibrary search path such as PATH on Windows or LD_LIBRARY_PATH onLinux. On macOS use init_oracle_client() in yourapplication to pass the Oracle Client directory name, seeUsing cx_Oracle.init_oracle_client() to set the Oracle Client directory. This is also usable on Windows.
Instant Client on Windows requires an appropriate Microsoft WindowsRedistributables, see Installing cx_Oracle on Windows. On Linux, the libaio(sometimes called libaio1) package is needed. Oracle Linux 8 alsoneeds the libnsl package.
Version 21 client libraries can connect to Oracle Database 12.1 or greater.Version 19, 18 and 12.2 client libraries can connect to Oracle Database 11.2or greater. Version 12.1 client libraries can connect to Oracle Database 10.2or greater. Version 11.2 client libraries can connect to Oracle Database 9.2or greater.
Locate your Oracle Database username and password, and the databaseconnection string. The connection string is commonly of the formathostname/servicename, using the hostname where the database isrunning, and using the service name of the Oracle Database instance.
cx_Oracle requires Oracle Client libraries. The libraries provide thenecessary network connectivity to access an Oracle Database instance.They also provide basic and advanced connection management and datafeatures to cx_Oracle.
cx_Oracle uses the shared library loading mechanism available on eachsupported platform to load the Oracle Client libraries at runtime. Itdoes not need to be rebuilt for different versions of the libraries.Since a single cx_Oracle binary can use different client versions andalso access multiple database versions, it is important yourapplication is tested in your intended release environments. NewerOracle clients support new features, such as the oraaccess.xml external configurationfile available with 12.1 or later clients, session pool improvements,improved high availability features, call timeouts, and other enhancements.
The cx_Oracle function clientversion() can be used todetermine which Oracle Client version is in use. The attributeConnection.version can be used to determine which Oracle Databaseversion a connection is accessing. These can then be used to adjust applicationbehavior accordingly. Attempts to use Oracle features that are not supported bya particular client/server library combination will result in runtime errors.
This will download and install a pre-compiled binary if one isavailable for yourarchitecture. If a pre-compiled binary is not available, the sourcewill be downloaded, compiled, and the resulting binary installed.Compiling cx_Oracle requires the Python.h header file. If you areusing the default python package, this file is in the python-develpackage or equivalent.
If you use optional Oracle configuration files such as tnsnames.ora,sqlnet.ora or oraaccess.xml with Instant Client, then put the filesin an accessible directory, for example in/opt/oracle/your_config_dir. Then use:
Alternatively, put the files in the network/admin subdirectory of InstantClient, for example in /opt/oracle/instantclient_21_1/network/admin.This is the default Oracle configuration directory for executables linkedwith this Instant Client.
Alternatively, for version 18 and earlier, every shell runningPython will need to have the environment variableLD_LIBRARY_PATH set to the appropriate directory for theInstant Client version. For example:
Alternatively, put the files in the network/admin subdirectory of InstantClient, for example in /usr/lib/oracle/21/client64/lib/network/admin.This is the default Oracle configuration directory for executables linkedwith this Instant Client.
This will download and install a pre-compiled binary if one isavailable for yourarchitecture. If a pre-compiled binary is not available, the sourcewill be downloaded, compiled, and the resulting binary installed.
Using cx_Oracle requires Oracle Client libraries to be installed.These provide the necessary network connectivity allowing cx_Oracleto access an Oracle Database instance. Oracle Client versions 19, 18,12 and 11.2 are supported.
If you use optional Oracle configuration files such as tnsnames.ora,sqlnet.ora or oraaccess.xml with Instant Client, then put the filesin an accessible directory, for example inC:\oracle\your_config_dir. Then use:
Alternatively, put the files in a network\admin subdirectory ofInstant Client, for example inC:\oracle\instantclient_19_11\network\admin. This is the defaultOracle configuration directory for executables linked with thisInstant Client.
If you use optional Oracle configuration files such as tnsnames.ora,sqlnet.ora or oraaccess.xml with Oracle Instant Client, then put thefiles in an accessible directory, for example in/Users/your_username/oracle/your_config_dir. Then use:
Alternatively, put the files in the network/admin subdirectory of OracleInstant Client, for example in/Users/your_username/Downloads/instantclient_19_8/network/admin. This is thedefault Oracle configuration directory for executables linked with thisInstant Client.
For other installation options such as installing through a proxy, seeinstructions above. Make sure the Oracle Client libraries are in the systemlibrary search path because cx_Oracle 7 does not support thecx_Oracle.init_oracle_client() method and does not support loading theOracle Client libraries from the directory containing the cx_Oracle modulebinary.
On Windows, if you are not usinginit_oracle_client(), then restart your command promptand use set PATH to check the environment variable has the correctOracle Client listed before any other Oracle directories.
On Linux, check the LD_LIBRARY_PATH environment variable containsthe Oracle Client library directory. If you are using Oracle InstantClient, a preferred alternative is to ensure a file in the/etc/ld.so.conf.d directory contains the path to the Instant Clientdirectory, and then run ldconfig.
A simple connection to the database requires an OracleDatabase user name and password and a databaseconnection string. For python-oracledb, a commonconnection string format is hostname:port/servicename, using the hostname where the database is running, the Oracle Database service name of thedatabase instance, and the port that the database is using. If the defaultport 1521 is being used, then this component of the connection string isoften omitted.
When python-oracledb is used in the default Thin mode, it connects directly tothe Oracle Database and does not require Oracle Client libraries. Connectionsin this mode can be made to Oracle Database 12.1 or later.
Any attempt to use Oracle Database features that are not supported by aparticular mode or client library/database combination will result in runtimeerrors. The python-oracledb attribute Connection.thin can be used tosee what mode a connection is in. In the Thick mode, the functionoracledb.clientversion() can be used to determine which Oracle Clientversion is in use. The attribute Connection.version can be used todetermine which Oracle Database version a connection is accessing. Theseattributes can then be used to adjust the application behavior accordingly.
The Python cryptography package. This package is automatically installed as adependency of python-oracledb. It is strongly recommended that you keep thecryptography package up to date whenever new versions are released. If thecryptography package is not available, you can still install python-oracledbbut can only use it in Thick mode, see Installing python-oracledb without the Cryptography Package.
This will download and install a pre-compiled binary from PyPI if one is available for yourarchitecture. Otherwise, the source will be downloaded, compiled, and theresulting binary installed. Compiling python-oracledb requires thePython.h header file. If you are using the default python package,this file is in the python-devel package or equivalent.
3a8082e126