Read pool autoscaling automatically adds or removes [read pool nodes](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#what-are-read-pools)
in the [read pool](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#what-are-read-pools)
based on your application's workload needs.

You can control read pool autoscaling by either limiting the average CPU
utilization across the read pool or by limiting the number of client connections
allowed access to the read pool, using one of two target metrics:

- **Average CPU utilization** : lets you set the average CPU usage you want the read pool to operate within. The read pool automatically [scales in or out](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#what_are_read_pools) based on your application's workload CPU usage.
- **Average database connections** : lets you specify the average number of client database connections that should be served by each node. The read pool automatically [scales in or out](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#what_are_read_pools) based on the number of client connections.

To apply these target metrics, you must also set a minimum and maximum read pool
node count.

To enable read pool autoscaling, you can configure one or both of these target
metrics on the instance. If both metrics are active, Cloud SQL applies
the maximum read pool node count indicated by both metrics.

The following table lists the limits for each target metric:

| Target metric name | Limits | Related public metric |
|---|---|---|
| Average CPU utilization | Between 0.1 and 0.9. | The [average CPU utilization](https://docs.cloud.google.com/sql/docs/sqlserver/admin-api/metrics.md.txt) (`cloudsql.googleapis.com/database/cpu/utilization`) across the read pool nodes in the read pool. |
| Average database connections | Between 10 and 32,767. Note: The maximum acceptable value correlates to the maximum value set by the `max_connections` database flag. | Represents an [average of database client connections](https://docs.cloud.google.com/sql/docs/sqlserver/admin-api/metrics.md.txt) (`cloudsql.googleapis.com/database/network/connections`) across the read pool nodes in the read pool. |

When the conditions are met to resize the read pool, read pool autoscaling
operations can be viewed from the Google Cloud console. All other operations on the
read pool and the primary instance are blocked until read pool autoscaling
completes.

## Read pool autoscaling characteristics

The following characteristics apply:

- Scale in operations remove only one node at a time.
- Scale out operations add, in parallel, as many nodes as needed.
- By default, both scale-in and scale-out operations are applied. You can optionally block scale-in operations by manually disabling them (`disableScaleIn`).
- By default, a cooldown period of 600 seconds is applied between successive read pool autoscaling operations. A minimum cooldown period of 60 seconds is required whether [scaling in or out](https://docs.cloud.google.com/sql/docs/sqlserver/read-pool-autoscaling.md.txt#gcloud-enable-existing-read-pool-with-autoscale).
- When setting a target metric, you must also define the minimum (`minNodeCount`) and maximum (`maxNodeCount`) read pool node count you want to use. If you enable autoscaling on an existing read pool, then the current read pool size must fall within the range you set.
- If [read pool nodes](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#what-are-read-pools) accrue higher CPU-usage specifically due to either replication overhead or non-SQL Server processes on the read pool nodes, then CPU-based autoscaling is throttled.

### Maximum read pool node count per primary instance

You can assign a maximum of seven read replicas per primary instance.

The combined number of read replicas and read pool nodes replicating from the
same primary instance can't exceed seven.

#### How to calculate maximum read pool node count per primary instance

Conceptually, you can think of a read replica as a single read pool node.

You can convert a read replica to a read pool, and then change the number of
read pool nodes to some number greater than one.

You can then assign autoscaling to the read pool so that the read pool node count
dynamically adjusts up or down to match workload needs.

When autoscaling is enabled on a read pool, you must indicate a valid maximum
node count for the read pool. That number, combined with the number of existing
read replicas replicating from the same primary, or read pool nodes belonging to
other read pools replicating from the same primary, can't exceed seven.

As an example, if a primary instance has two read replicas, and one read pool
with two read pool nodes, and a second read pool with autoscaling enabled, the
maximum read pool node count for the second read pool can't be a value greater
than three.

### Limitations

The following limitations apply:

- If you want to create a new read pool or scale an existing read pool, then you must wait for previous create and scaling operations to complete. This applies to operations associated with the read pool as well as other read pools associated with the same primary instance. If you try to run concurrent operations, you might receive the following error message:

  ```
  Operation failed because another operation was already in progress.
  ```

## Before you begin

- Make sure you complete all required [prerequisite steps](https://docs.cloud.google.com/sql/docs/sqlserver/create-read-pool.md.txt#before_you_begin)
  to create a read pool.

- Make sure to use [`gcloud` version 544.0.0](https://docs.cloud.google.com/sdk/docs/release-notes.md.txt#54400_2025-10-21)
  or later.

- Make sure to use [Terraform provider version](https://github.com/hashicorp/terraform-provider-google/releases/tag/v7.8.0)
  7.8.0 or later.

## Create a read pool with autoscaling enabled

If you specify a target value of 0.50 for `AVERAGE_CPU_UTILIZATION`,
read pool nodes will be added or removed from the read pool to keep the average
CPU utilization across the read pool at 0.50 or less.

### gcloud

To create a read pool with autoscaling enabled, run the following:

```bash
  gcloud sql instances create READ_POOL_NAME \
  --tier=MACHINE_TIER --edition=ENTERPRISE_PLUS \
  --instance-type=READ_POOL_INSTANCE --node-count=NODE_COUNT \
  --database-version=DATABASE_VERSION \
  --master-instance-name=PRIMARY_INSTANCE_NAME \
  --region=REGION --network=NETWORK_NAME \
  --no-assign-ip \
  --auto-scale-enabled \
  --auto-scale-max-node-count=MAX_NODE_COUNT \
  --auto-scale-min-node-count=MIN_NODE_COUNT \
  --auto-scale-target-metrics=TARGET_METRIC_1=VALUE_1
  
```

Replace the following:

- <var translate="no">READ_POOL_NAME</var>: the name you want to assign the read pool.
- <var translate="no">MACHINE_TIER</var>: the machine tier you want to use, such as `db-perf-optimized-N-2`.
- <var translate="no">NODE_COUNT</var>: the read pool node count you want to start with.
- <var translate="no">DATABASE_VERSION</var>: the database version you want to use, such as `SQLSERVER_2022_ENTERPRISE`.
- <var translate="no">PRIMARY_INSTANCE_NAME</var>: the name of the primary instance you want to use.
- <var translate="no">REGION</var>: the region you want to use, such as `us-east1`.
- <var translate="no">NETWORK_NAME</var>: the name of the network you want to use.
- <var translate="no">MAX_NODE_COUNT</var>: the maximum number of read pool nodes you want the read pool to use, such as `5`.
- <var translate="no">MIN_NODE_COUNT</var>: the minimum number of read pool nodes you want the read pool to use, such as `1`.
- <var translate="no">TARGET_METRIC_1</var>: the target metric you want to use, such as the following:
  - `AVERAGE_CPU_UTILIZATION`
  - `AVERAGE_DB_CONNECTIONS`
  You must define at least one of the two available metrics.
- <var translate="no">VALUE_1</var>: the value you want to assign for the target metric you previously indicated. For example, for the `AVERAGE_CPU_UTILIZATION` target metric, you might assign the value `0.50`.

### Terraform

To create a read pool with autoscaling enabled, use a
[Terraform resource](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance).

The following example includes resources for the primary instance and
the read pool.

```terraform

resource "random_password" "root_password" {
  length  = 24
  special = true
}

resource "google_sql_database_instance" "primary" {
  name             = "sqlserver-primary"
  database_version = "SQLSERVER_2019_ENTERPRISE"
  region           = "europe-west4"
  root_password    = random_password.root_password.result
  instance_type    = "CLOUD_SQL_INSTANCE"

  settings {
    tier    = "db-perf-optimized-N-2"
    edition = "ENTERPRISE_PLUS"

    backup_configuration {
      enabled                        = true
      point_in_time_recovery_enabled = true
    }

    ip_configuration {
      ipv4_enabled = true
    }
  }
}

resource "google_sql_database_instance" "read_pool" {
  name                 = "sqlserver-read-pool"
  database_version     = "SQLSERVER_2019_ENTERPRISE"
  region               = "europe-west4"
  master_instance_name = google_sql_database_instance.primary.name
  instance_type        = "READ_POOL_INSTANCE"
  node_count           = 2

  settings {
    tier    = "db-perf-optimized-N-2"
    edition = "ENTERPRISE_PLUS"

    ip_configuration {
      ipv4_enabled = true
    }

    read_pool_auto_scale_config {
      enabled                    = true
      min_node_count             = 2
      max_node_count             = 5
      disable_scale_in           = false
      scale_in_cooldown_seconds  = 600
      scale_out_cooldown_seconds = 600

      target_metrics {
        metric       = "AVERAGE_CPU_UTILIZATION"
        target_value = 0.5
      }
    }
  }
}
```

#### Apply the changes

To apply your Terraform configuration in a Google Cloud project, complete the steps in the
following sections.

## Prepare Cloud Shell

1. Launch [Cloud Shell](https://shell.cloud.google.com/).
2. Set the default Google Cloud project
   where you want to apply your Terraform configurations.

   You only need to run this command once per project, and you can run it in any directory.

   ```
   export GOOGLE_CLOUD_PROJECT=PROJECT_ID
   ```

   Environment variables are overridden if you set explicit values in the Terraform
   configuration file.

## Prepare the directory

Each Terraform configuration file must have its own directory (also
called a *root module*).

1. In [Cloud Shell](https://shell.cloud.google.com/), create a directory and a new file within that directory. The filename must have the `.tf` extension---for example `main.tf`. In this tutorial, the file is referred to as `main.tf`.

   ```
   mkdir DIRECTORY && cd DIRECTORY && touch main.tf
   ```
2. If you are following a tutorial, you can copy the sample code in each section or step.

   Copy the sample code into the newly created `main.tf`.

   Optionally, copy the code from GitHub. This is recommended
   when the Terraform snippet is part of an end-to-end solution.
3. Review and modify the sample parameters to apply to your environment.
4. Save your changes.
5. Initialize Terraform. You only need to do this once per directory.

   ```
   terraform init
   ```

   Optionally, to use the latest Google provider version, include the `-upgrade`
   option:

   ```
   terraform init -upgrade
   ```

## Apply the changes

1. Review the configuration and verify that the resources that Terraform is going to create or update match your expectations:

   ```
   terraform plan
   ```

   Make corrections to the configuration as necessary.
2. Apply the Terraform configuration by running the following command and entering `yes` at the prompt:

   ```
   terraform apply
   ```

   Wait until Terraform displays the "Apply complete!" message.
3. [Open your Google Cloud project](https://console.cloud.google.com/) to view the results. In the Google Cloud console, navigate to your resources in the UI to make sure that Terraform has created or updated them.

> [!NOTE]
> **Note:** Terraform samples typically assume that the required APIs are enabled in your Google Cloud project.

#### Delete the changes

To delete your changes, do the following:

1. To disable deletion protection, in your Terraform configuration file set the `deletion_protection` argument to `false`.

   ```
   deletion_protection =  "false"
   ```
2. Apply the updated Terraform configuration by running the following command and entering `yes` at the prompt:

   ```
   terraform apply
   ```

<!-- -->

3. Remove resources previously applied with your Terraform configuration by running the following
   command and entering `yes` at the prompt:

   ```
   terraform destroy
   ```

### REST v1

To create a read pool with autoscaling enabled, use a POST request with the
[instances:insert](https://docs.cloud.google.com/sql/docs/sqlserver/admin-api/rest/v1/instances/insert.md.txt)
method.


Before using any of the request data,
make the following replacements:

- <var translate="no">READ_POOL_NAME</var>: the name you want to assign the read pool.
- <var translate="no">REGION</var>: the region where you want the instance to reside, such as `us-central1`.
- <var translate="no">PRIMARY_INSTANCE_ID</var>: the ID of the primary instance you want to use.
- <var translate="no">PROJECT_ID</var>: the ID of the project where you want the read pool to be located, such as `my-project-name`.
- <var translate="no">DATABASE_VERSION</var>: the database version you want to use, such as `SQLSERVER_2022_ENTERPRISE`.
- <var translate="no">MACHINE_TIER</var>: the machine tier you want to use, such as `db-perf-optimized-N-2`.
- <var translate="no">FULL_NETWORK_NAME</var>: the name of the network you want to use.
- <var translate="no">MAX_NODE_COUNT</var>: the maximum number of read pool nodes you want the read pool instance to use, such as `7`. You can assign a maximum of seven read pool nodes per primary instance. For more information, see [Maximum node count](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#maximum-node-count).
- <var translate="no">MIN_NODE_COUNT</var>: the minimum number of read pool nodes you want the read pool to use, such as `2`.
- <var translate="no">TARGET_METRIC_1</var>: the target metric you want to use, such as `AVERAGE_CPU_UTILIZATION` or `AVERAGE_DB_CONNECTIONS`. You must define at least one of the two available metrics.
- <var translate="no">VALUE_1</var>: the value you want to assign for the target metric you previously indicated. For example, for the `AVERAGE_CPU_UTILIZATION` target metric, you might assign the value `0.50`.
- <var translate="no">NODE_COUNT</var>: the read pool node count you want to start with, such as `3`.


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances
```


Request JSON body:

```
{
  "name":"READ_POOL_NAME",
  "region":"REGION",
  "masterInstanceName":"PRIMARY_INSTANCE_ID",
  "project":"PROJECT_ID",
  "databaseVersion":"DATABASE_VERSION",
  "settings":{
    "tier":"MACHINE_TIER",
    "edition":"ENTERPRISE_PLUS",
    "ipConfiguration":{
      "privateNetwork":"FULL_NETWORK_NAME",
      "ipv4Enabled": false
    },
    "readPoolAutoScaleConfig":{
      "enabled": true,
      "minNodeCount": MIN_NODE_COUNT,
      "maxNodeCount": MAX_NODE_COUNT,
      "targetMetrics": [
        {
          "metric":"TARGET_METRIC_1",
          "targetValue": VALUE_1
        }
      ]
    }
  },
  "instanceType":"READ_POOL_INSTANCE",
  "nodeCount": NODE_COUNT
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_ID",
  "status": "RUNNING",
  "user": "user@example.com",
  "insertTime": "2020-01-16T02:32:12.281Z",
  "startTime": "2023-06-14T18:48:35.499Z",
  "operationType": "CREATE",
  "name": "OPERATION_ID",
  "targetId": "PRIMARY_INSTANCE_ID",
  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
  "targetProject": "PROJECT_ID"
}
```

### REST v1beta4

To create a read pool with autoscaling enabled, use a POST request with the
[instances:insert](https://docs.cloud.google.com/sql/docs/sqlserver/admin-api/rest/v1beta4/instances/insert.md.txt)
method.


Before using any of the request data,
make the following replacements:

- <var translate="no">READ_POOL_NAME</var>: the name you want to assign the read pool.
- <var translate="no">REGION</var>: the region where you want the instance to reside, such as `us-central1`.
- <var translate="no">PRIMARY_INSTANCE_ID</var>: the ID of the primary instance you want to use.
- <var translate="no">PROJECT_ID</var>: the ID of the project where you want the read pool to be located, such as `my-project-name`.
- <var translate="no">DATABASE_VERSION</var>: the database version you want to use, such as `SQLSERVER_2022_ENTERPRISE`.
- <var translate="no">MACHINE_TIER</var>: the machine tier you want to use, such as `db-perf-optimized-N-2`.
- <var translate="no">FULL_NETWORK_NAME</var>: the name of the network you want to use.
- <var translate="no">MAX_NODE_COUNT</var>: the maximum number of read pool nodes you want the read pool instance to use, such as `7`. You can assign a maximum of seven read pool nodes per primary instance. For more information, see [Maximum node count](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#maximum-node-count).
- <var translate="no">MIN_NODE_COUNT</var>: the minimum number of read pool nodes you want the read pool to use, such as `2`.
- <var translate="no">TARGET_METRIC_1</var>: the target metric you want to use, such as the following:
  - `AVERAGE_CPU_UTILIZATION`
  - `AVERAGE_DB_CONNECTIONS`
  You must define at least one of the two available metrics.
- <var translate="no">VALUE_1</var>: the value you want to assign for the target metric you previously indicated. In this example, for the `AVERAGE_CPU_UTILIZATION` target metric, assign the value `0.50`.
- <var translate="no">NODE_COUNT</var>: the read pool node count you want to start with, such as `3`.


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances
```


Request JSON body:

```
{
  "name":"READ_POOL_NAME",
  "region":"REGION",
  "masterInstanceName":"PRIMARY_INSTANCE_ID",
  "project":"PROJECT_ID",
  "databaseVersion":"DATABASE_VERSION",
  "settings":{
    "tier":"MACHINE_TIER",
    "edition":"ENTERPRISE_PLUS",
    "ipConfiguration":{
      "privateNetwork":"FULL_NETWORK_NAME",
      "ipv4Enabled": false
    },
    "readPoolAutoScaleConfig":{
      "enabled": true,
      "minNodeCount": MIN_NODE_COUNT,
      "maxNodeCount": MAX_NODE_COUNT,
      "targetMetrics": [
        {
          "metric":"TARGET_METRIC_1",
          "targetValue": VALUE_1
        }
      ]
    }
  },
  "instanceType":"READ_POOL_INSTANCE",
  "nodeCount": NODE_COUNT
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/PRIMARTY_INSTANCE_ID",
  "status": "RUNNING",
  "user": "user@example.com",
  "insertTime": "2020-01-16T02:32:12.281Z",
  "startTime": "2023-06-14T18:48:35.499Z",
  "operationType": "CREATE",
  "name": "OPERATION_ID",
  "targetId": "PRIMARTY_INSTANCE_ID",
  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
  "targetProject": "PROJECT_ID"
}
```

## Enable read pool autoscaling on an existing read pool

If you already have a read pool created, then you can enable autoscaling by
indicating the autoscaling configuration you want to use.

For example, if you specify a target value of `50` for
`AVERAGE_DB_CONNECTIONS`, nodes will be added or removed from the
read pool to keep the average database connections across the pool at 50 or less.

### gcloud

To enable read pool with autoscaling on an existing read pool, run the
following command.

```bash
  gcloud sql instances patch INSTANCE
  --auto-scale-enabled
  --auto-scale-max-node-count=MAX_NODE_COUNT
  --auto-scale-min-node-count=MIN_NODE_COUNT
  --auto-scale-out-cooldown-seconds=COOLDOWN_SECONDS_SCALE_OUT
  --auto-scale-in-cooldown-seconds=COOLDOWN_SECONDS_SCALE_IN
  --auto-scale-target-metrics=TARGET_METRIC_1=VALUE_1
  
```

Replace the following:

- <var translate="no">INSTANCE_NAME</var>: the instance name associated with the read pool you want to modify.
- <var translate="no">MAX_NODE_COUNT</var>: the maximum number of read pool nodes you want the read pool to use, such as `7`. You can assign a maximum of 7 read pool nodes per primary instance. For more information, see [Maximum node count](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#maximum-node-count).
- <var translate="no">MIN_NODE_COUNT</var>: the minimum number of read pool nodes you want the read pool to use, such as `2`.
- <var translate="no">COOLDOWN_SECONDS_SCALE_OUT</var>: Optional: the cooldown or wait time in seconds between read pool node creation or deletion, such as `180`. A minimum cooldown period of 60 seconds is required. The default value is 600 seconds.
- <var translate="no">COOLDOWN_SECONDS_SCALE_IN</var>: Optional: the cooldown or wait time in seconds between read pool node creation or deletion, such as `180`. A minimum cooldown period of 60 seconds is required. The default value is 600 seconds.
- <var translate="no">TARGET_METRIC_1</var>: the target metric you want to use, such as the following:
  - `AVERAGE_CPU_UTILIZATION`
  - `AVERAGE_DB_CONNECTIONS`
  You must define at least one of the two available metrics.
- <var translate="no">VALUE_1</var>: the value you want to assign for the target metric you previously indicated. In this example, for the `AVERAGE_DB_CONNECTIONS` target metric, assign the value `50`.

### REST v1

To enable an existing read pool with autoscaling, use the
[PATCH](https://docs.cloud.google.com/sql/docs/sqlserver/admin-api/rest/v1/instances/patch.md.txt) method.


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the ID or [project number](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifying_projects) of the Google Cloud project that contains the instance.
- <var translate="no">INSTANCE_ID</var>: the ID of the instance associated with the read pool.
- <var translate="no">MAX_NODE_COUNT</var>: the maximum number of read pool nodes you want the read pool instance to use, such as `7`. You can assign a maximum of seven read pool nodes per primary instance. For more information, see [Maximum node count](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#maximum-node-count).
- <var translate="no">MIN_NODE_COUNT</var>: the minimum number of read pool nodes you want the read pool to use, such as `2`.
- <var translate="no">COOLDOWN_SECONDS</var>: Optional: the cooldown or wait time in seconds between read pool node creation or deletion, such as `180`.
- <var translate="no">SCALE_IN_DISABLED</var>: Optional: lets you disable [read pool scale in](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#what_are_read_pools) behavior. To disable read pool scale-in, set the value to `true`.
- <var translate="no">TARGET_METRIC_1</var>: the target metric you want to use, such as the following:
  - `AVERAGE_CPU_UTILIZATION`
  - `AVERAGE_DB_CONNECTIONS`
  You must define at least one of the two available metrics.
- <var translate="no">VALUE_1</var>: the value you want to assign for the target metric you previously indicated. In this example, for the `AVERAGE_DB_CONNECTIONS` target metric, assign the value `50`.


HTTP method and URL:

```
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID
```


Request JSON body:

```
{
  "settings": {
    "readPoolAutoScaleConfig": {
      "enabled": true,
      "minNodeCount": MIN_NODE_COUNT,
      "maxNodeCount": MAX_NODE_COUNT,
      "scaleOutCooldownSeconds": COOLDOWN_SECONDS,
      "disableScaleIn": SCALE_IN_DISABLED,
      "targetMetrics": [
        {
          "metric": "TARGET_METRIC_1",
          "targetValue": VALUE_1
        }
      ]
    }
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X PATCH \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method PATCH `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID",
  "status": "RUNNING",
  "user": "user@example.com",
  "insertTime": "2020-01-16T02:32:12.281Z",
  "startTime": "2023-06-14T18:48:35.499Z",
  "operationType": "UPDATE",
  "name": "OPERATION_ID",
  "targetId": "INSTANCE_ID",
  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
  "targetProject": "PROJECT_ID"
}
```

### REST v1beta4

To enable an existing read pool with autoscaling, use the
[PATCH](https://docs.cloud.google.com/sql/docs/sqlserver/admin-api/rest/v1beta4/instances/patch.md.txt)
method.


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the ID or [project number](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifying_projects) of the Google Cloud project that contains the instance.
- <var translate="no">INSTANCE_ID</var>: the ID of the instance associated with the read pool.
- <var translate="no">MAX_NODE_COUNT</var>: the maximum number of read pool nodes you want the read pool instance to use, such as `7`. You can assign a maximum of seven read pool nodes per primary instance. For more information, see [Maximum node count](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#maximum-node-count).
- <var translate="no">MIN_NODE_COUNT</var>: the minimum number of read pool nodes you want the read pool to use, such as `2`.
- <var translate="no">COOLDOWN_SECONDS</var>: Optional: the cooldown or wait time in seconds between read pool node creation or deletion, such as `180`.
- <var translate="no">SCALE_IN_DISABLED</var>: Optional: lets you disable [read pool scale in](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt#what_are_read_pools) behavior. To disable read pool scale-in, set the value to `true`.
- <var translate="no">TARGET_METRIC_1</var>: the target metric you want to use, such as the following:
  - `AVERAGE_CPU_UTILIZATION`
  - `AVERAGE_DB_CONNECTIONS`
  You must define at least one of the two available metrics.
- <var translate="no">VALUE_1</var>: the value you want to assign for the target metric you previously indicated. In this example, for the `AVERAGE_DB_CONNECTIONS` target metric, assign the value `50`.


HTTP method and URL:

```
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID
```


Request JSON body:

```
{
  "settings": {
    "readPoolAutoScaleConfig": {
      "enabled": true,
      "minNodeCount": MIN_NODE_COUNT,
      "maxNodeCount": MAX_NODE_COUNT,
      "scaleOutCooldownSeconds": COOLDOWN_SECONDS,
      "disableScaleIn": SCALE_IN_DISABLED,
      "targetMetrics": [
        {
          "metric": "TARGET_METRIC_1",
          "targetValue": VALUE_1
        }
      ]
    }
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X PATCH \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method PATCH `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID",
  "status": "RUNNING",
  "user": "user@example.com",
  "insertTime": "2020-01-16T02:32:12.281Z",
  "startTime": "2023-06-14T18:48:35.499Z",
  "operationType": "UPDATE",
  "name": "OPERATION_ID",
  "targetId": "INSTANCE_ID",
  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
  "targetProject": "PROJECT_ID"
}
```

## Disable read pool autoscaling on a read pool

Complete the following steps to disable read pool autoscaling.

### gcloud

To disable read pool autoscaling, run the following command.

```bash
  gcloud sql instances patch INSTANCE_NAME
  --no-auto-scale-enabled
  
```

Replace the following:

- <var translate="no">INSTANCE_NAME</var>: the instance name associated with the read pool you want to modify.

### REST v1

To disable read pool autoscaling, use the
[PATCH](https://docs.cloud.google.com/sql/docs/sqlserver/admin-api/rest/v1/instances/patch.md.txt) method.


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the ID or [project number](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifying_projects) of the Google Cloud project that contains the instance.
- <var translate="no">INSTANCE_ID</var>: the ID of the instance associated with the read pool.


HTTP method and URL:

```
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID
```


Request JSON body:

```
{
  "settings":{
    "readPoolAutoScaleConfig":{
      "enabled": false
    }
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X PATCH \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method PATCH `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID",
  "status": "RUNNING",
  "user": "user@example.com",
  "insertTime": "2020-01-16T02:32:12.281Z",
  "startTime": "2023-06-14T18:48:35.499Z",
  "operationType": "CREATE",
  "name": "OPERATION_ID",
  "targetId": "INSTANCE_ID",
  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
  "targetProject": "PROJECT_ID"
}
```

### REST v1beta4

To disable read pool autoscaling, use the
[PATCH](https://docs.cloud.google.com/sql/docs/sqlserver/admin-api/rest/v1beta4/instances/patch.md.txt)
method.


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the ID or [project number](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifying_projects) of the Google Cloud project that contains the instance.
- <var translate="no">INSTANCE_ID</var>: the ID of the instance associated with the read pool.


HTTP method and URL:

```
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID
```


Request JSON body:

```
{
  "settings":{
    "readPoolAutoScaleConfig":{
      "enabled": false
    }
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X PATCH \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method PATCH `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID",
  "status": "RUNNING",
  "user": "user@example.com",
  "insertTime": "2020-01-16T02:32:12.281Z",
  "startTime": "2023-06-14T18:48:35.499Z",
  "operationType": "CREATE",
  "name": "OPERATION_ID",
  "targetId": "INSTANCE_ID",
  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
  "targetProject": "PROJECT_ID"
}
```

## View metrics

Use [system insights](https://docs.cloud.google.com/sql/docs/sqlserver/use-system-insights.md.txt) to view relevant
metrics for your read pool.

For `AVERAGE_CPU_UTILIZATION`, refer to the **CPU utilization** [key metric chart](https://docs.cloud.google.com/sql/docs/sqlserver/use-system-insights.md.txt#metrics).

For `AVERAGE_DB_CONNECTIONS`, refer to the **Total connections** [key metric chart](https://docs.cloud.google.com/sql/docs/sqlserver/use-system-insights.md.txt#metrics)..

## Monitor read pool autoscaling operations

When the conditions are met to trigger a read pool autoscaling event, an `UPDATE`
operation runs on the instance. You can view this operation from the Google Cloud console.

Read pool autoscaling operations can take 10 minutes or longer to apply to the
instance. Any existing connections won't be transferred to newly added read pool
nodes, meaning only new connections will be impacted by read pool autoscaling.

While the autoscaling operation is running on the read pool, you must wait for
it to finish before running other updates on the read pool or on the primary
instance. If you try to run concurrent requests, you might receive the following
error message:

<br />

```
  Operation failed because another operation was already in progress.
  
```

<br />

You can inspect your read pool instance and see the node count change:

<br />

```bash
  gcloud sql instances describe READ_POOL_NAME
  | grep nodeCount
  
```

<br />

Replace the following:

- <var translate="no">READ_POOL_NAME</var>: the name of the read pool for which you want to get information.

### System event audit logs

You can also see the [system event](https://docs.cloud.google.com/sql/docs/sqlserver/audit-logging.md.txt#system-events)
audit log message associated with method `cloudsql.instances.readPoolAutoScale`,
which contains the old and new node count.

## What's next

- [About read pools](https://docs.cloud.google.com/sql/docs/sqlserver/about-read-pools.md.txt)
- [Create a read pool](https://docs.cloud.google.com/sql/docs/sqlserver/create-read-pool.md.txt)