Connect from an Arm-based A1 Compute Shape to Autonomous Database Two Ways

May 28, 2021 | 3 minute read
Text Size 100%:

This week we made Arm-based servers available in Oracle Cloud Infrastructure, including a generous free offering with 4 cores and 24 GB of RAM of Ampere A1 Compute as part of our Always Free tier. Todd Sharp wrote a cool blog post showing how to create your own Minecraft Server using one of these Free Tier A1 shapes.

Connecting to an Oracle Autonomous Database from an A1 shape two ways: SQLcl and Python

In this blog post I’ll demonstrate how to connect from an A1 shape running Oracle Linux 8 to Autonomous Database two ways:

  1. using SQLcl
  2. using Python 3.8 with the cx_Oracle module.

Pre-requisites

For these examples, it’s assumed you have the following already running:

Installing and connecting SQLcl to Oracle Autonomous Database

Over on the Database blog, Gerald Venzl covered how SQLcl recently became easier to obtain and install. I’ll use some of his techniques to install SQLcl on my Arm-based A1 shape.

Download Client Credentials (Wallet) and copy to A1 instance.

scp -i <path to ssh private key> Wallet_<database name>.zip opc@<public IP address>

Install a JDK, download and unzip SQLcl

As I’m writing this blog post, there isn’t a SQLcl RPM available yet in the yum repositories for aarch64. Not a problem, the latest SQLcl is available under the Oracle Free Use Terms and Conditions license and you can download it using curl. SQLcl connects using the Thin JDBC driver, which is platform-independent and does not require any additional Oracle software on the client-side.

sudo dnf install jdk
curl -O https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip
unzip sqlcl-latest.zip
chmod 755 sqlcl/bin/sql

Launch SQLcl, configure it to use your client credentials, and connect

My Autonomous Database is called testdb, and the wallet I downloaded is Wallet_testdb.zip. The Wallet zip contains a tnsnames.ora that contains several connect descriptors for your Autonomous Database. Here I’m using <database name>_high. I use the set cloudconfig command to point SQLcl to the Wallet zip archive.

sqlcl/bin/sql /nolog
set cloudconfig /home/opc/oracle/wallets/testdb/Wallet_testdb.zip
Operation is successfully completed.
Operation is successfully completed.
Using temp directory:/tmp/oracle_cloud_config3986877764276892824
SQL> connect admin@testdb_high
Password? (**********?) ************
Connected.
SQL> select sysdate from dual;
SYSDATE 
____________ 
27-MAY-21     

Connecting Python to Oracle Database using the cx_Oracle module.

These are the steps to connect Python 3.8 to Oracle Autonomous Database using the cx_Oracle module. While we offer cx_Oracle RPMs Oracle Linux on x86_64, they aren’t available for aarch64 yet as I’m writing this post. Instead of an RPM-based package, I’m going to use pip to install from PyPi. cx_Oracle depends on Oracle Instant Client, so I install that first.

Install Python 3.8 and cx_Oracle Oracle Instant Client

sudo dnf module install python38
sudo dnf install python38-pip python38-devel
python3.8 -m pip install --user cx_Oracle

Install Oracle Instant Client

sudo dnf install oracle-release-el8
sudo dnf install oracle-instantclient19.10-basic

Connecting

[opc@a1 testdb]$ python3.8
Python 3.8.6 (default, Apr  9 2021, 14:43:42) 
[GCC 8.4.1 20200928 (Red Hat 8.4.1-1.0.1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
import cx_Oracle
>>> con = cx_Oracle.connect('admin', '<YOUR PASSWORD>', 'testdb_high')
>>> print("Database version:", con.version)
Database version: 21.2.0.0.0

Conclusion

In this blog post, I explained how to connect from both SQLcl and Python 3.8 on an Arm-based A1 shape running Oracle Linux 8 to Oracle Autonomous Database.

Sergio Leunissen


Previous Post

Announcing the release of Oracle Linux 8 Update 4

Simon Coter | 4 min read

Next Post


Exploring ARM64 runtime patching alternatives

Thomas Tai | 12 min read