This page describes how to configure Managed Connection Pooling (MCP) for your Cloud SQL instances.
Before you begin
- Confirm that your instance meets all requirements to use MCP.
- If you're using gcloud CLI, then your gcloud CLI version must
be
515.0.0
or later. - Confirm that your instance is using the new Cloud SQL network architecture. If your instance is still using the old network architecture, then upgrade to the new network architecture.
You can enable MCP for an instance at time of creation, or edit an existing instance to enable it.
Enable MCP for a new instance
To create an instance with MCP enabled, see Create instances. You can enable MCP for an instance using the Google Cloud console, gcloud CLI, or the Cloud SQL API.
Enable MCP for an existing instance
You can enable MCP for an existing instance using the Google Cloud console, gcloud CLI, or the Cloud SQL API. You must enable MCP before modifying MCP options.
Console
In the Google Cloud console, go to the Cloud SQL Instances page.
Find the instance you want to enable MCP for. To open the Overview page of the instance, click the instance name.
Click Edit.
Under Customize your instance, expand Connections.
To enable MCP, check the box for Enable Managed Connection Pool.
Click Save.
gcloud
To enable MCP for an existing instance, do the following:
gcloud sql instances patch INSTANCE_NAME
--enable-connection-pooling
Replace the following:
INSTANCE_NAME
: the name of the Cloud SQL instance that you want to enable MCP for.
REST v1
To enable MCP for an existing instance, use the following
command and set connectionPoolingEnabled
:
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID
- INSTANCE_ID: the instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID
Request JSON body:
{ "settings": { "connectionPoolConfig": { "connectionPoolingEnabled": true } } }
To send your request, expand one of these options:
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": "PENDING", "user": "user@example.com", "insertTime": "2020-01-16T02:32:12.281Z", "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 MCP for an existing instance, use the following
command and set connectionPoolingEnabled
:
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID
- INSTANCE_ID: the instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID
Request JSON body:
{ "settings": { "connectionPoolConfig": { "connectionPoolingEnabled": true } } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/instances/INSTANCE_ID", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-16T02:32:12.281Z", "operationType": "UPDATE", "name": "OPERATION_ID", "targetId": "INSTANCE_ID", "selfLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }
Modify MCP for an instance
After you enable MCP, you can customize MCP using the available configuration options. These configuration options are called MCP pool flags. Configurations added to MCP are applied to all poolers used by the instance. For more information on the available configuration options, their default values, and ranges, see available configurations options.
To modify the available MCP configuration options for an instance, do the following:
Console
In the Google Cloud console, go to the Cloud SQL Instances page.
Find the instance you want to enable MCP for. To open the Overview page of the instance, click the instance name.
Click Edit.
Under Customize your instance, expand Connections.
Under Managed connection pool, expand Advanced pooling options.
Modify the available pooling options that you want to update.
Click Save.
gcloud
gcloud sql instances patch INSTANCE_NAME
--connection-pool-flags=CONFIGURATION_NAME=CONFIGURATION_VALUE
Replace the following:
INSTANCE_NAME
: the name of the Cloud SQL instance that you want to disable MCP for.CONFIGURATION_NAME
: the name of the configuration option you want to modify. For a list of all available configuration options, see available configurations options.CONFIGURATION_VALUE
: the new value for the configuration option that that you selected.
REST v1
To modify MCP
available configurations,
use the following command and set ConnectionPoolConfig
:
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID
- INSTANCE_ID: the instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID
Request JSON body:
{ "settings": { "connectionPoolConfig": { "connectionPoolingEnabled": true } } }
To send your request, expand one of these options:
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": "PENDING", "user": "user@example.com", "insertTime": "2020-01-16T02:32:12.281Z", "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 modify MCP
available configurations,
use the following command and set ConnectionPoolConfig
:
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID
- INSTANCE_ID: the instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID
Request JSON body:
{ "settings": { "connectionPoolConfig": { "connectionPoolingEnabled": true } } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/instances/INSTANCE_ID", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-16T02:32:12.281Z", "operationType": "UPDATE", "name": "OPERATION_ID", "targetId": "INSTANCE_ID", "selfLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }
Disable MCP for an instance
You can disable MCP for an existing instance using the Google Cloud console, gcloud CLI, or the Cloud SQL API.
To disable MCP for an instance, do the following:
Console
In the Google Cloud console, go to the Cloud SQL Instances page.
Find the instance you want to disable MCP for. To open the Overview page of the instance, click the instance name.
Click Edit.
Under Customize your instance, expand Connections.
To disable MCP, clear the box for Enable Managed Connection Pool.
Click Save.
gcloud
To disable MCP for an existing instance, do the following:
gcloud sql instances patch INSTANCE_NAME
--no-enable-connection-pooling
Replace the following:
PROJECT_ID
: the name of the Cloud SQL instance that you want to disable MCP for.
REST v1
To disable MCP for an instance, use the following
command and set connectionPoolingEnabled
:
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID
- INSTANCE_ID: the instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID
Request JSON body:
{ "settings": { "connectionPoolConfig": { "connectionPoolingEnabled": true } } }
To send your request, expand one of these options:
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": "PENDING", "user": "user@example.com", "insertTime": "2020-01-16T02:32:12.281Z", "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 disable MCP for an instance, use the following
command and set connectionPoolingEnabled
:
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID
- INSTANCE_ID: the instance ID
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID
Request JSON body:
{ "settings": { "connectionPoolConfig": { "connectionPoolingEnabled": true } } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/instances/INSTANCE_ID", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-16T02:32:12.281Z", "operationType": "UPDATE", "name": "OPERATION_ID", "targetId": "INSTANCE_ID", "selfLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }
View MCP status for an instance
You can view the status of MCP for an instance using the Google Cloud console, gcloud CLI, or the Cloud SQL API.
To view the status of MCP for a Cloud SQL Enterprise Plus edition instance, do the following:
Console
In the Google Cloud console, go to the Cloud SQL Instances page.
Find the instance you want to disable MCP for. To open the Overview page of the instance, click the instance name.
The Connections section shows whether MCP is enabled or disabled.
gcloud
gcloud sql instances describe INSTANCE_NAME| grep connectionPoolingEnabled
Replace the following:
PROJECT_ID
: the name of the Cloud SQL instance that you want to view MCP status for.If MCP is enabled, the following response is returned:
connectionPoolingEnabled: true
REST v1
To view the status of MCP for your Cloud SQL
instance, use the following command and look for ConnectPoolingEnabled
:
Before using any of the request data, make the following replacements:
- PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance.
- INSTANCE_NAME: the name of the Cloud SQL instance. If this instance has Private Service Connect enabled for it, then Private Service Connect endpoints in VPC networks can connect to it.
HTTP method and URL:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "kind": "sql#instance", "state": "RUNNABLE", "databaseVersion": "POSTGRES_13", "settings": { "authorizedGaeApplications": [], "tier": "db-custom-2-7680", "kind": "sql#settings", "availabilityType": "REGIONAL", "pricingPlan": "PER_USE", "replicationType": "SYNCHRONOUS", "activationPolicy": "ALWAYS", "ipConfiguration": { "authorizedNetworks": [], "pscConfig": { "allowedConsumerProjects": [ "ALLOWED_PROJECTS" ], "pscEnabled": true }, "ipv4Enabled": false }, ... "createTime": "2023-06-14T18:48:34.975Z", "sqlNetworkArchitecture": "NEW_NETWORK_ARCHITECTURE", "pscServiceAttachmentLink": "projects/PROJECT_ID/regions/REGION_NAME/serviceAttachments/SERVICE_ATTACHMENT_ID", "dnsName": "DNS_NAME" }
REST v1beta4
To view the status of MCP for your Cloud SQL
instance, use the following command and look for ConnectPoolingEnabled
:
Before using any of the request data, make the following replacements:
- PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance.
- INSTANCE_NAME: the name of the Cloud SQL instance. If this instance has Private Service Connect enabled for it, then Private Service Connect endpoints in VPC networks can connect to it.
HTTP method and URL:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_NAME
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "kind": "sql#instance", "state": "RUNNABLE", "databaseVersion": "POSTGRES_13", "settings": { "authorizedGaeApplications": [], "tier": "db-custom-2-7680", "kind": "sql#settings", "availabilityType": "REGIONAL", "pricingPlan": "PER_USE", "replicationType": "SYNCHRONOUS", "activationPolicy": "ALWAYS", "ipConfiguration": { "authorizedNetworks": [], "pscConfig": { "allowedConsumerProjects": [ "ALLOWED_PROJECTS" ], "pscEnabled": true }, "ipv4Enabled": false }, ... "createTime": "2023-06-14T18:48:34.975Z", "sqlNetworkArchitecture": "NEW_NETWORK_ARCHITECTURE", "pscServiceAttachmentLink": "projects/PROJECT_ID/regions/REGION_NAME/serviceAttachments/SERVICE_ATTACHMENT_ID", "dnsName": "DNS_NAME" }
Monitor Managed Connection Pooling (MCP)
You can monitor how Managed Connection Pooling (MCP) is running on your Cloud SQL instances using the following Cloud SQL MCP metrics:
Metric name | Description |
---|---|
num_pools | The total number of connection pools per database. |
client_connection | Tracks the connection count by the status of the client
connection. The statuses included in this metric are:
|
server_connections | Tracks the server connections count by the status of the
server connection. The statuses included in this metric
are:
|
client_connections_avg_wait_time | The average time spent by all clients in waiting state for a server. |
For more information about these metrics, see Cloud SQL metrics. To view these metrics using the Google Cloud console, see View metrics on the Cloud SQL instance overview page.