This post walks through the steps to create and connect to an Oracle Autonomous Database (Free edition) by using the Oracle Cloud Infrastructure CLI and SQL*Plus in Oracle Cloud Infrastructure Cloud Shell. The prerequisites for trying this out yourself are signing up for a Free Tier account (or using a current tenancy) and same basic Linux shell skills.
Cloud Shell is a web browser-based terminal accessible from the Oracle Cloud Console and available to all Oracle Cloud Infrastructure users. It’s free to use (within monthly tenancy limits), and it provides access to a Linux shell with a pre-authenticated CLI and other useful tools for following Oracle Cloud Infrastructure service tutorials and labs. The Cloud Shell appears in the Console as a persistent frame and stays active as you navigate to different parts of the Console.
Oracle Cloud Infrastructure’s Autonomous Database is a fully managed, preconfigured database environment with two workload types available: Autonomous Transaction Processing and Autonomous Data Warehouse. You don’t need to configure or manage any hardware, or install any software. After provisioning, you can scale the number of CPU cores or the storage capacity of the database at any time without impacting availability or performance.
After you create a free account (if necessary), you follow these steps to create and connect to an Autonomous Database using Cloud Shell. The rest of this post walks through the steps in detail.
You can download all the commands in the following steps from a GitHub repository. And the good news is that the Cloud Shell environment contains Git, too, so you can just clone the repo into your Cloud Shell environment.
I also recommend using tmux so you don't lose your session. Here is a good cheat sheet.
Sign in to your Oracle Cloud Infrastructure tenancy and click the command prompt icon in Console header.
This creates the Cloud Shell environment, where you run all the commands and connect to the Autonomous Database.
You can also open the Cloud Shell directly by constructing a URL like the following one, where you replace <region> and <tenancy> with your values:
https://console.us-<region>-1.oraclecloud.com/a/<tenancy>?cloudshell=true
Clone the Git repo. Git is preinstalled with Cloud Shell.
andy_tael@cloudshell:oci_cs_adb (us-ashburn-1)$ git clone https://github.com/andytael/oci_cs_adb
To avoid making changes to the Git repository from Cloud Shell, change the directory to the working directory and remove the remote origin. (But, feel free to create a branch and participate in or improve the repo.)
andy_tael@cloudshell:oci_cs_adb (us-ashburn-1)$ cd oci_cs_adb
andy_tael@cloudshell:oci_cs_adb (us-ashburn-1)$ git remote remove origin
You should have the following files in the Git working directory:
Using vim, edit the env_vars.sh file to set the comp_name and db_name variables. Then, save the file.
andy_tael@cloudshell:oci_cs_adb (us-ashburn-1)$ vi env_vars.sh
Set the environment variables.
andy_tael@cloudshell:oci_cs_adb (us-ashburn-1)$ source env_vars.sh
Cloud Shell has the Oracle Cloud Infrastructure CLI preinstalled, and you use the CLI to get data (and create resources). Get the OCID for the department where you will deploy the Autonomous Database.
andy_tael@cloudshell:oci_cs_adb (us-ashburn-1)$ source get_ocid_comp.sh
The command should return the OCID of the compartment. If not, verify your environment variables.
Run the following command to create an Autonomous Database (Autonomous Transaction Processing, or OLTP) in the compartment specified in ocid_comp (in step 3). The name and display name (used in the Console) are specified in the db_name variable. The admin password for the database is specified in the db_pwd variable.
andy_tael@cloudshell:oci_cs_adb (us-ashburn-1)$ source create_atp_free.sh
This process might take few minutes. You can check the status of the creation of the Autonomous Database by using the check_atp_status.sh script or the Console.
andy_tael@cloudshell:oci_cs_adb (us-ashburn-1)$ source check_atp_status.sh
You need the OCID for the Autonomous Database to download the wallet files. Run the following command.
andy_tael@cloudshell:oci_cs_adb (us-ashburn-1)$ source get_adb_ocid.sh
To connect to the Autonomous Database, you need the wallet file. Run the following command to create the necessary directory structure and unzip the wallet.
andy_tael@cloudshell:oci_cs_adb (us-ashburn-1)$ source get_wallet.sh
Modify the sqlnet.ora file to reflect where the wallet files are by running the following command. A copy of the original sqlnet.ora file is stored in the $TNS_ADMIN location.
andy_tael@cloudshell:oci_cs_adb (us-ashburn-1)$ source fix_sqlnet.sh
If everything has run properly, you can connect to the Autonomous Database by running the following command from Cloud Shell:
sqlplus admin/${db_pwd}@${conn_string}
Exit SQL*Plus by using the QUIT command.
Happy testing and coding!
@
Because my compartment is a child compartment, I added the --access-level to include only those too which I had INSPECT granted , and the --compartment-id-in-subtree with --all due to my compartment being a child. The new command that returned my compartment_id became:
"ocid_comp=$(oci iam compartment list --access-level ACCESSIBLE --compartment-id-in-subtree TRUE --all --query "data [?"name"=='${comp_name}'] | [0].id" --raw-output)"