Build a Ruby Application
To build a Ruby application that accesses an Autonomous Database, you start by configuring your development system to support database access that can take advantage of the continuous availability and high performance features of Autonomous Database.
After configuring your development system to support database access, you code database connections and SQL statements in your application to take advantage of these features.
Parent topic: Build Database Applications with Autonomous Database
Configure Your Ruby Development System
To configure your development system so that your Ruby application can take advantage of the continuous availability and high performance features of an Autonomous Database, you perform these steps.
- Download and install Ruby.
- Download and install Oracle Instant Client.
- Download and install ruby-oci8.
- Download the client credentials for the database and make them available to Oracle Instant Client.
Before You Begin
Your development system must meet certain criteria to configure it successfully.
-
It must have internet access.
-
It must have network access to the Autonomous Database.
Download and Install Ruby
To download and install Ruby, go to the Installing Ruby page at ruby-lang.org and follow the instructions for your system's OS and architecture.
Download and Install Oracle Instant Client
Download and install the Oracle Instant Client basic package for your system's OS and architecture:
-
Oracle Linux:
Run these commands to download and install the Oracle Instant Client basic package:
sudo yum -y install oracle-release-el7 sudo yum -y install oracle-instantclient19.3-basic
(If you want to see a list of all Instant Client packages, go to
http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/index.html
.) -
Other OSes and architectures:
-
Go to the Oracle Instant Client Downloads page and select the download for your system's OS and architecture.
-
On the download page, accept the Oracle Technology Network License Agreement, download the latest version of the Basic Package, and then install it by following the instructions at the bottom of the download page.
-
Download and Install ruby-oci8
To download and install the ruby-oci8 interface to Oracle Database, follow the instructions in the Install for Oracle Instant Client page.
Download and Install Client Credentials for the Database
-
Download the zip file containing client credentials for your database to a secure directory on your computer.
This zip file is available for download from the database's Details page in the Oracle Cloud console. Download the credentials as follows.
-
In your web browser, sign in to Oracle Cloud and navigate to the Details page for the Autonomous Database.
-
Click DB Connection.
-
On the Database Connection page click Download.
-
In the Download Wallet dialog, enter a wallet password in the Password field and confirm the password in the Confirm Password field.
The password must be at least 8 characters long and must include at least 1 letter and either 1 numeric character or 1 special character.
-
Click Download to save the client credentials zip file to a secure directory.
-
-
After downloading the zip file, follow these steps:
-
Unzip the client credentials zip file.
-
Edit the
sqlnet.ora
file provided in the client credentials, replacing"?/network/admin"
with the full path of the directory where you unzipped the client credentials; for example, change:(DIRECTORY="?/network/admin")
to:
(DIRECTORY="/users/jdoe/adbcredentials")
-
Create the
TNS_ADMIN
environment variable, setting its value to the full path of the directory where you unzipped the client credentials.
-
Parent topic: Build a Ruby Application
Code Database Connections and SQL Statements
After configuring your development system to support Ruby application connectivity to an Autonomous Database, follow these guidelines to achieve high performance and continuous availability of your application's connections to the database:
- Use connection pools.
- Enable FAN (Fast Application Notification).
- Use the predefined database service that best matches the operations you will be performing. For information about the predefined database services, see Predefined Database Service Names for Autonomous Databases.
For example:
require 'oci8'
OCI8.properties[:events_mode] = true
cpool = OCI8::ConnectionPool.new(1, 5, 2, username, password, 'tp_tls')
conn1 = OCI8.new(username, password, cpool)
This example enables FAN by setting the
events_mode
property to true
, creates a pool for
connections to the tp_tls
database service, and acquires a connection
from the pool.
Additional Resources
For detailed information about ruby-oci8, go to the Ruby-oci8 page.
Parent topic: Build a Ruby Application