Help Center/ TaurusDB/ API Reference/ APIs (Recommended)/ Instance Management/ Configuring an Auto Scaling Policy
Updated on 2026-01-05 GMT+08:00

Configuring an Auto Scaling Policy

Function

This API is used to configure an auto scaling policy. Before calling this API:

Calling Method

For details, see Calling APIs.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.

  • If you are using role/policy-based authorization, see Permissions and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependency

    gaussdbformysql:autoscaling:createPolicy

    Permission_management

    instance *

    • g:EnterpriseProjectId

    • g:ResourceTag/<tag-key>

    gaussdb:autoscaling:createPolicy

    -

URI

PUT /v3/{project_id}/instances/{instance_id}/auto-scaling/policy

Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition

Project ID of a tenant in a region.

To obtain this value, see Obtaining a Project ID.

Constraints

N/A

Range

The value contains 32 characters. Only letters and digits are allowed.

Default Value

N/A

instance_id

Yes

String

Definition

Instance ID, which uniquely identifies an instance.

Constraints

N/A

Range

The value contains 36 characters with a suffix of in07. Only letters and digits are allowed.

Default Value

N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition

User token. To obtain this value, call the IAM API for obtaining a user token.

The value of X-Subject-Token in the response header is the token value.

Constraints

N/A

Range

N/A

Default Value

N/A

Content-Type

Yes

String

Definition

Content type.

Constraints

N/A

Range

application/json

Default Value

application/json

X-Language

No

String

Definition

Request language type.

Constraints

N/A

Range

  • en-us

  • zh-cn

Default Value

en-us

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

status

Yes

String

Definition

Whether auto scaling is enabled.

Constraints

N/A

Range

  • ON: Auto scaling is enabled.

  • OFF: Auto scaling is disabled.

Default Value

N/A

scaling_strategy

Yes

ScalingStrategyReqInfo object

Definition

Configuration of an auto scaling policy.

Constraints

N/A

monitor_cycle

No

Integer

Definition

Observation period, in seconds.

During the entire observation period, if the average CPU usage is greater than or equal to the preset value, a scale-up is triggered.

Constraints

This parameter is mandatory when status is set to ON.

Range

300, 600, 900, 1800

Default Value

N/A

silence_cycle

No

Integer

Definition

Silent period, in seconds.

It indicates the minimum interval between two auto scale-up operations or two auto scale-down operations.

Constraints

This parameter is mandatory when status is set to ON.

Range

300, 600, 1800, 3600, 7200, 10800, 86400, 604800

Default Value

N/A

enlarge_threshold

No

Integer

Definition

Average CPU usage (%).

Constraints

This parameter is mandatory when status is set to ON.

Range

50–100

Default Value

N/A

max_flavor

No

String

Definition

Maximum specifications.

Constraints

This parameter is mandatory when the instance specifications are automatically scaled up or down. The vCPU/memory ratio of the new specifications must be the same as that of the original specifications.

Range

N/A

Default Value

N/A

reduce_enabled

No

Boolean

Definition

Whether to enable auto scale-down.

Constraints

This parameter is mandatory when auto scaling is enabled.

Range

  • true: Auto scale-down is enabled.

  • false: Auto scale-down is disabled.

Default Value

N/A

max_read_only_count

No

Integer

Definition

Maximum number of read replicas.

Constraints

This parameter is mandatory when the function for adding or deleting read replicas is enabled.

Range

2–15

Default Value

N/A

read_only_weight

No

Integer

Definition

Read weight of read replicas.

Constraints

This parameter is mandatory when the function for adding or deleting read replicas is enabled.

Range

N/A

Default Value

0–1000

Table 4 ScalingStrategyReqInfo

Parameter

Mandatory

Type

Description

flavor_switch

Yes

String

Definition

Whether instance specifications can be automatically scaled up or down.

Constraints

N/A

Range

  • ON: Instance specifications can be automatically scaled up or down.

  • OFF: Instance specifications cannot be automatically scaled up or down.

Default Value

N/A

read_only_switch

Yes

String

Definition

Whether to enable the function for adding or deleting read replicas.

Constraints

To use this function, ensure that there is only one proxy instance. For details about how to create a proxy instance, see Creating a Proxy Instance.

Range

  • ON: The function for adding or deleting read replicas is enabled.

  • OFF: The function for adding or deleting read replicas is disabled.

Default Value

N/A

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

instance_id

String

Definition

Instance ID.

Range

The value contains 36 characters with a suffix of in07. Only letters and digits are allowed.

instance_name

String

Definition

Instance name.

Range

The name must start with a letter and consist of 4 to 64 characters. Only letters (case-sensitive), digits, hyphens (-), and underscores (_) are allowed.

switch_status

AutoScalingSwitchStatus object

Definition

Switch status.

Table 6 AutoScalingSwitchStatus

Parameter

Type

Description

scaling_switch

String

Definition

Whether auto scaling is enabled.

Range

  • ON: Auto scaling is enabled.

  • OFF: Auto scaling is disabled.

flavor_switch

String

Definition

Whether instance specifications are automatically scaled up or down.

Range

  • ON: Instance specifications are automatically scaled up or down.

  • OFF: Instance specifications are not automatically scaled up or down.

read_only_switch

String

Definition

Whether the function for adding or deleting read replicas is enabled.

Range

  • ON: The function for adding or deleting read replicas is enabled.

  • OFF: The function for adding or deleting read replicas is disabled.

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 500

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Request

Configuring an auto scaling policy

PUT https://{endpoint}/v3/97b026aa9cc4417888c14c84a1ad9860/instances/61a4ea66210545909d74a05c27a7179ein07/auto-scaling/policy

{
  "enlarge_threshold" : 50,
  "max_flavor" : "gaussdb.mysql.large.x86.4",
  "max_read_only_count" : 2,
  "monitor_cycle" : 300,
  "read_only_weight" : 10,
  "reduce_enabled" : false,
  "scaling_strategy" : {
    "flavor_switch" : "ON",
    "read_only_switch" : "ON"
  },
  "silence_cycle" : 300,
  "status" : "ON"
}

Example Response

Status code: 200

Success.

{
  "instance_id" : "61a4ea66210545909d74a05c27a7179ein07",
  "instance_name" : "gauss-test-1",
  "switch_status" : {
    "scaling_switch" : "ON",
    "flavor_switch" : "ON",
    "read_only_switch" : "ON"
  }
}

SDK Sample Code

The SDK sample code is as follows.

Configuring an auto scaling policy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.gaussdb.v3.region.GaussDBRegion;
import com.huaweicloud.sdk.gaussdb.v3.*;
import com.huaweicloud.sdk.gaussdb.v3.model.*;


public class UpdateAutoScalingPolicySolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        GaussDBClient client = GaussDBClient.newBuilder()
                .withCredential(auth)
                .withRegion(GaussDBRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateAutoScalingPolicyRequest request = new UpdateAutoScalingPolicyRequest();
        request.withInstanceId("{instance_id}");
        UpdateAutoScalingPolicyRequestBody body = new UpdateAutoScalingPolicyRequestBody();
        ScalingStrategyReqInfo scalingStrategybody = new ScalingStrategyReqInfo();
        scalingStrategybody.withFlavorSwitch("ON")
            .withReadOnlySwitch("ON");
        body.withScalingStrategy(scalingStrategybody);
        body.withReadOnlyWeight(10);
        body.withMaxReadOnlyCount(2);
        body.withReduceEnabled(false);
        body.withMaxFlavor("gaussdb.mysql.large.x86.4");
        body.withEnlargeThreshold(50);
        body.withSilenceCycle(300);
        body.withMonitorCycle(300);
        body.withStatus("ON");
        request.withBody(body);
        try {
            UpdateAutoScalingPolicyResponse response = client.updateAutoScalingPolicy(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Configuring an auto scaling policy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkgaussdb.v3 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = GaussDBClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateAutoScalingPolicyRequest()
        request.instance_id = "{instance_id}"
        scalingStrategybody = ScalingStrategyReqInfo(
            flavor_switch="ON",
            read_only_switch="ON"
        )
        request.body = UpdateAutoScalingPolicyRequestBody(
            scaling_strategy=scalingStrategybody,
            read_only_weight=10,
            max_read_only_count=2,
            reduce_enabled=False,
            max_flavor="gaussdb.mysql.large.x86.4",
            enlarge_threshold=50,
            silence_cycle=300,
            monitor_cycle=300,
            status="ON"
        )
        response = client.update_auto_scaling_policy(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Configuring an auto scaling policy

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := gaussdb.NewGaussDBClient(
        gaussdb.GaussDBClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateAutoScalingPolicyRequest{}
	request.InstanceId = "{instance_id}"
	scalingStrategybody := &model.ScalingStrategyReqInfo{
		FlavorSwitch: "ON",
		ReadOnlySwitch: "ON",
	}
	readOnlyWeightUpdateAutoScalingPolicyRequestBody:= int32(10)
	maxReadOnlyCountUpdateAutoScalingPolicyRequestBody:= int32(2)
	reduceEnabledUpdateAutoScalingPolicyRequestBody:= false
	maxFlavorUpdateAutoScalingPolicyRequestBody:= "gaussdb.mysql.large.x86.4"
	enlargeThresholdUpdateAutoScalingPolicyRequestBody:= int32(50)
	silenceCycleUpdateAutoScalingPolicyRequestBody:= int32(300)
	monitorCycleUpdateAutoScalingPolicyRequestBody:= int32(300)
	request.Body = &model.UpdateAutoScalingPolicyRequestBody{
		ScalingStrategy: scalingStrategybody,
		ReadOnlyWeight: &readOnlyWeightUpdateAutoScalingPolicyRequestBody,
		MaxReadOnlyCount: &maxReadOnlyCountUpdateAutoScalingPolicyRequestBody,
		ReduceEnabled: &reduceEnabledUpdateAutoScalingPolicyRequestBody,
		MaxFlavor: &maxFlavorUpdateAutoScalingPolicyRequestBody,
		EnlargeThreshold: &enlargeThresholdUpdateAutoScalingPolicyRequestBody,
		SilenceCycle: &silenceCycleUpdateAutoScalingPolicyRequestBody,
		MonitorCycle: &monitorCycleUpdateAutoScalingPolicyRequestBody,
		Status: "ON",
	}
	response, err := client.UpdateAutoScalingPolicy(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Code

For details, see Status Codes.

Error Code

For details, see Error Codes.