Oracle Autonomous Database is a family of self-driving, self-securing, and self-repairing cloud services. These databases eliminate human labor, human error, and manual tuning, reducing cost and complexity and ensuring higher reliability, security, and more operational efficiency. Currently, Autonomous Database is offered in two configurations – Autonomous Data Warehouse and Autonomous Transaction Processing.
This blog talks about how the OCI Command Line Interface can be used to manage autonomous databases. It describes the process of how you can run the CLI Scripts from an OCI Compute VM, how you can automate the process, and how to use Instance Principals so you do not need a user’s private keys for authentication. It gives examples of a few commands for managing automated databases and gives references so you can easily implement other commands. It describes the following commands:
The client has a workload that is not uniformly distributed throughout the day. Most of the workload is from 1:00 AM in the night till 6:00 AM in the morning. Rest of the day the workload is much lighter. The client will like to scale up the ATP OCPUs just before 1:00 AM and scale OCPUs down after 6:00 AM. Moreover, they have a UAT instance that is used for acceptance testing and load tests. UAT is used only on the days when testing has to be performed. It is not used on most of the days.
As a result of their requirements the client will like the following:
A simple way to implement this is by using OCI CLI scripts that are automated using cron jobs. These scripts should use OCI Instance Principals for authentication. The rest of the blog describes how this is implemented.
The OCI Command Line Interface is a small footprint tool that you can use to complete Oracle Cloud Infrastructure tasks. The CLI provides the same core functionality as the Console, plus some additional commands. Some of these, such as the ability to run scripts extend the Console's functionality.
You can run OCI CLI on any Mac, Windows, or Linux computer running Python that has access to Oracle Cloud Infrastructure public services. Although you can run OCI CLI from your desktops or laptops we recommend that you run it from an OCI VM, especially if you want to manage production databases. This has several advantages:
In this blog, I use an OCI VM running Linux for running the OCI CLI scripts. To manage an autonomous database using OCI CLI scripts you will need to do the following:
You should identify a Linux VM from where you will run the automated CLI Scripts. You do not need a dedicated VM to run these scripts. But, if there are other administrator scripts that you use, it may be worth dedicating a VM for running the admin scripts.
The details to install OCI on a Linux Compute in OCI are given here. Or you can just follow the Quick Start guide to install the CLI. For the use case discussed in this blog, you will not be running the CLI scripts using a user’s credentials, thus you can skip the directions regarding creating a user, and creating certificates, etc. If you are using Oracle Linux 7 Compute, you can also just install OCI CLI by connecting to your VM using ssh and then using yum:
$sudo yum install python36-oci-cli |
After installing the OCI CLI, you need to create the config file. The config file must be created in ~/.oci folder. The config file needs to have the following three lines:
[DEFAULT] Tenancy=< tenancy ocid > Region=< your region > |
The config file should be present in ~/.oci folder, and only the owner should have rw permissions, as shown below:
[opc@vm .oci]$pwd |
Next, you need to create a dynamic group, and a policy that will allow you to use OCI CLI from a compute VM using Instance Principals. The compute from where you will run the CLI scripts should be a member of the Dynamic Group. The policies should grant the dynamic group permissions to manage autonomous database family. If you are not sure how to do this, please see my other blog Calling OCI CLI Using Instance Principal.
The OCI CLI to manage autonomous database is given here - click on Command Line Reference, Database Service (db), and then on autonomous-database.
Below are sample scripts to start, stop, and update the autonomous databases. These scripts are valid both for AWD and ATP databases. Make sure the path to OCI CLI is included in the PATH variable. In my system, the OCI CLI was installed at $HOME/bin directory. Depending on the method you used to install OCI CLI, it may be installed at a different location.
Script to start autonomous database:
#!/bin/bash |
Script to stop autonomous database:
#!/bin/bash |
Script to change number of OCPUs in autonomous database:
#!/bin/bash |
The last step is to create a cron job to execute these scripts as per your desired schedule. Your Linux administrator should be able to create the cron jobs. I used crontab -e command to set up cron jobs as follows:
Edit the corn table using crontab -e command from root user:
#crontab -e |
Enter your cron commands, for example:
SHELL=/bin/bash |