Note:

Set Up Database autoscaling using Oracle Cloud Infrastructure Cloud Native Services

Introduction

Setting up autoscaling is part of and requirement of every team hosting their applications on cloud.

For database instances like Oracle Autonomous Data Warehouse (ADW) and Oracle Autonomous Transaction Processing (ATP), we can set up autoscaling using Oracle Cloud Infrastructure (OCI) cloud native services.

Objectives

Prerequisites

Task 1: Set up required IAM policies and dynamic groups

  1. Log in to OCI console using this link.

  2. Once logged in, go to IAM Dynamic Group and create a new dynamic group as below:

    Create Dynamic Group

  3. Provide the compartment OCID to the rule as below. Your database instance should exist in this compartment:

    Setup Dynamic Group

  4. Go to IAM policies and create an IAM policy with this statement:

    allow dynamic-group dynamic_group_name to manage autonomous-database-family in compartment compartment_name

Task 2: Create and deploy the function code

  1. Go to functions/applications and create a function. This function will use the IAM Dynamic Group and Policy to access the ADW and perform the required scaling (both up and down) when the function is triggered. Follow the steps on screen to create the function. We have used Python to code the required logic, but you can use your own language and change the logic as needed. To write the code, open the function requirement.txt file and func.py file in OCI Cloud Shell and write the code.

    Deploy Function

  2. Get the full function code from this repo, it also uses the OCI Resource Principals so that you don’t have to worry about keeping your OCI credentials here.

  3. Once you have finished writing the code, update the function in registry and deploy the latest code using this command on the cloud shell:

    fn -v deploy — app e2e-function-demo

  4. Once deployed, your function is ready to be invoked. You can try to test using the function invoke command and once you are sure the function is working as required, you can move to next section.

    DEBUG=1 fn invoke e2e-function-demo e2e-fn-streaming

NOTE:

Task 3: Set up notifications and configure alarm

  1. Let’s create a topic which will trigger the function created. Go to Notifications, Topic and create a topic.

    Create Topic

  2. Then create a subscription in the created topic and point it to function created.

    Create Subscription

    Now our topic is also configured.

  3. We need to set up the alarm, provide a trigger condition and then add the Topic created above as trigger destination. For this, go to the desired database instance and scroll down to the metric for which you want to create the alarm on, and click on the options and then click Create an alarm on this query option.

    Create Alarm

    1. Fill details like name and description and select the severity

      Define Alarm

    2. Set up the metric description, provide values for metric namespace, name, interval and statistic.

      Alarm Metric Description

    3. Provide the details for metric dimensions and trigger rule. You can also set the trigger rule using advanced query as described in this doc: Building Metric Queries.

      Alarm Trigger

    4. Provide the created topic details which will trigger the function when the condition matches.

      Alarm Destination

  4. Save the alarm. This will trigger the alarm and invoke the function when the condition matches.

Acknowledgments

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.