Stay organized with collections Save and categorize content based on your preferences.
This page describes how to create a read replica for a Cloud SQL instance.
To set up a Cloud SQL instance to act as a publisher to an external subscriber, see Configure external replicas.
Important: Before using this feature, review About replication in Cloud SQL, including the Limitations. Additionally, note that this feature only applies to the following versions of Cloud SQL for SQL Server: SQL Server 2017 Enterprise, SQL Server 2019 Enterprise, and SQL Server 2022 Enterprise.A read replica is a copy of the primary instance that reflects changes to the primary in almost real time, in normal circumstances. You can use a read replica to offload read requests or analytics traffic from the primary instance.
Additionally, for disaster recovery, you can perform a regional migration. If a replica is a cross-region replica, you can perform a failover to another region; specifically, you can promote a replica to a standalone instance (in which case, existing replicas would not consider that instance as primary).
For more information about how replication works, see Replication in Cloud SQL.
Before you beginIf you are creating the first replica for this instance, ensure that the instance meets the requirements for primary instances. Learn more.
Create a read replicaWhen creating a read replica, keep the following considerations in mind:
The steps for creating a read replica are below.
Note: If the primary instance has a private IP connection and the instance accepts database connections from Cloud SQL Language Connectors only, then you can't create read replicas for the instance. ConsoleIn the Google Cloud console, go to the Cloud SQL Instances page.
more actions
menu next to the listing.If you don't see that choice, then the instance is a replica; you can't create a replica of a replica.
In the Customize your instance section, update settings for your replica. Begin by clicking Show configuration options to display the groups of settings. Then, expand the desired groups to review and customize the settings. A Summary of all the options you select appears on the right. Customizing these settings is optional. Defaults are assigned in every case where no customizations are made.
For more details about each setting, see the About instance settings page.
Cloud SQL creates a backup, if needed, and creates the replica. You are returned to the instance page for the primary.
Create the replica:
gcloud sql instances create REPLICA_NAME \ --master-instance-name=PRIMARY_INSTANCE_NAMEYou can specify a different tier size using the
--tier
parameter, if needed. You can specify a different region using the --region
parameter. If the primary instance has an internal IP address only, then add the --no-assign-ip
parameter to the command.
You can add more parameters for other instance settings. To learn more, see gcloud sql instances create.
You must create the replica in the same VPC network as the primary instance. You can also specify anallocated-ip-range-name
in that VPC network. If no range is specified, the replica is created in a random range. Terraform
To create a read replica, use a Terraform resource.
REST v1beta4Use the insert
method of the instances resource to create the read replica. The region and databaseVersion properties must be the same as the master.
Before using any of the request data, make the following replacements:
ipv4Enabled
parameter to false
because you want the Cloud SQL instance to be associated with a private IP address, not a public IP one.
HTTP method and URL:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances
Request JSON body:
{ "masterInstanceName": "primary-instance-name", "project": "project-id", "databaseVersion": "database-version", "name": "replica-name", "region": "replica-region", "settings": { "tier": "machine-type", "settingsVersion": 0, } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-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"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
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:
Response{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "CREATE_REPLICA", "name": "operation-id", "targetId": "instance-id", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id", "targetProject": "project-id" }Create a read replica of an instance with Private Service Connect enabled
To create a read replica of an instance with Private Service Connect enabled, use gcloud CLI or the API. You can create this replica in either the same region or in a different region from the primary instance (cross-region read replica).
The read replica can't replicate from an instance with a different connectivity type. For example, an instance with Private Service Connect enabled can replicate only from another Private Service Connect instance. It also can't replicate from an instance that supports external IP connections or from an instance that's configured with private services access.
gcloudTo create a read replica of an instance, use the gcloud sql instances create
command:
gcloud sql instances create REPLICA_INSTANCE_NAME \ --master-instance-name=PRIMARY_INSTANCE_NAME \ --project=PROJECT_ID \ --region=REGION_NAME \ --enable-private-service-connect \ --allowed-psc-projects=ALLOWED_PROJECTS \ --availability-type=AVAILABILITY_TYPE \ --no-assign-ip
Make the following replacements:
ALLOWED_PROJECTS: a list of allowed project IDs or numbers, separated by commas. If a project isn't contained in this list, then you can't use it to create an instance and enable Private Service Connect for it.
Cloud SQL doesn't copy the allowed projects for the primary instance over to the replica. For each replica, you must create a Private Service Connect endpoint. If you're using the Cloud SQL Auth Proxy or Cloud SQL Language Connectors, then create a DNS zone and DNS record for the replicas.
REGIONAL
: enable high availability and is recommended for production instances. The instance fails over to another zone within your selected region.ZONAL
: provide no failover capability. This is the default value.For more information about setting and removing high availability for instances, see Configure an existing instance for high availability and Deactivate high availability for an instance.
Before using any of the request data, make the following replacements:
REGIONAL
: enable high availability and is recommended for production instances. The instance fails over to another zone within your selected region.ZONAL
: provide no failover capability. This is the default value.For more information about setting and removing high availability for instances, see Configure an existing instance for high availability and Deactivate high availability for an instance.
ALLOWED_PROJECTS: a list of allowed project IDs or numbers, separated by commas. If a project isn't contained in this list, then you can't use it to create an instance and enable Private Service Connect for it.
Cloud SQL doesn't copy the allowed projects for the primary instance over to the replica. For each replica, you must create a Private Service Connect endpoint. If you're using the Cloud SQL Auth proxy or Cloud SQL Language Connectors, then you must create a DNS zone and DNS record for the replicas.
HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances
Request JSON body:
{ "masterInstanceName": "PRIMARY_INSTANCE_NAME", "project": "PROJECT_ID", "databaseVersion": "SQLSERVER_2019_STANDARD", "name": "REPLICA_INSTANCE_NAME", "region": "REGION_NAME", "kind": "sql#instance", "settings": { "tier": "MACHINE_TYPE", "availabilityType": "AVAILABILITY_TYPE", "settingsVersion": 0, "ipConfiguration": { "ipv4Enabled": false, "pscConfig": { "allowedConsumerProjects": [ALLOWED_PROJECTS], "pscEnabled": true } }, "kind": "sql#settings", "pricingPlan": "PER_USE", "replicationType": "ASYNCHRONOUS", "tier": "MACHINE_TYPE" } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-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"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
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/REPLICA_INSTANCE_NAME", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-16T02:32:12.281Z", "operationType": "CREATE_REPLICA", "name": "OPERATION_ID", "targetId": "REPLICA_INSTANCE_NAME", "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }REST v1beta4
Before using any of the request data, make the following replacements:
REGIONAL
: enable high availability and is recommended for production instances. The instance fails over to another zone within your selected region.ZONAL
: provide no failover capability. This is the default value.For more information about setting and removing high availability for instances, see Configure an existing instance for high availability and Deactivate high availability for an instance.
ALLOWED_PROJECTS: a list of allowed project IDs or numbers, separated by commas. If a project isn't contained in this list, then you can't use it to create an instance and enable Private Service Connect for it.
Cloud SQL doesn't copy the allowed projects for the primary instance over to the replica. For each replica, you must create a Private Service Connect endpoint. If you're using the Cloud SQL Auth proxy or Cloud SQL Language Connectors, then you must create a DNS zone and DNS record for the replicas.
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances
Request JSON body:
{ "masterInstanceName": "PRIMARY_INSTANCE_NAME", "project": "PROJECT_ID", "databaseVersion": "SQLSERVER_2019_STANDARD", "name": "REPLICA_INSTANCE_NAME", "region": "REGION_NAME", "kind": "sql#instance", "settings": { "tier": "MACHINE_TYPE", "availabilityType": "AVAILABILITY_TYPE", "settingsVersion": 0, "ipConfiguration": { "ipv4Enabled": false, "pscConfig": { "allowedConsumerProjects": [ALLOWED_PROJECTS], "pscEnabled": true } }, "kind": "sql#settings", "pricingPlan": "PER_USE", "replicationType": "ASYNCHRONOUS", "tier": "MACHINE_TYPE" } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X PATCH \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-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"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
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" | 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/REPLICA_INSTANCE_NAME", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-16T02:32:12.281Z", "operationType": "CREATE_REPLICA", "name": "OPERATION_ID", "targetId": "REPLICA_INSTANCE_NAME", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }Create cascading replicas
This section describes how to create and manage cascading replicas.
For information about how cascading replicas work, see Cascading replicas.
Before you beginThe primary instance must have a cascadable replica. The following section provides the steps to create a cascadable replica.
Steps to create a cascadable replicaWhen you create a cascadable replica, you must create the replica in a different region than the primary instance. You configure a cascadable replica by setting the cascadable-replica
flag.
Create the new replica by specifying the primary instance using the --master-instance-name
flag and using the --cascadable-replica
flag:
gcloud sql instances create REPLICA_NAME \ --master-instance-name=PRIMARY_INSTANCE_NAME \ --cascadable-replica \ --region=REGION
Replace the following:
You must create the replica in the same VPC network as the primary instance. You can also specify an allocated IP range name in that VPC network. If no range is specified, then the replica is created in a random range.
You can add more parameters for other instance settings. For example,
--tier
parameter.--no-assign-ip
parameter to the command.For more information adding parameters for instance settings, see gcloud sql instances create.
After the cascadable replica is created, you can create a cascading replica.
curlrequest.json
.
Before using any of the request data, make the following replacements:
SQLSERVER_2017_ENTERPRISE.
db-custom-2-3840
.{ "masterInstanceName": "PRIMARY_INSTANCE_NAME", "project": "PROJECT_ID", "databaseVersion": "DATABASE_VERSION" "name": "REPLICA_NAME", "region": "REPLICA_REGION", "settings": { "tier": "MACHINE_TYPE", "settingsVersion": 0, } "replicaConfiguration": { "cascadableReplica": true } }
replicaConfiguration
section, make sure that the cascadadableReplica
field is set to true
.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"
After the cascadable replica is created, you can create a cascading replica.
Steps to create a cascading replicaWhen you create a cascading replica, you must create the replica in the same region as the cascadable replica. You configure a cascading replica by providing the name of the cascadable replica in the
–master-instance-name
parameter.
ConsoleIn the Google Cloud console, go to the Cloud SQL Instances page.
Cloud SQL creates a replica. You're returned to the instance page for the parent replica.
--master-instance-name
flag:gcloud sql instances create REPLICA_NAME \ --master-instance-name=CASCADABLE_REPLICA_NAME \Replace the following:
request.json
:
{ "masterInstanceName": "CASCADABLE_REPLICA_NAME", "project": "PROJECT_ID", "name": "REPLICA_NAME", "region": "REPLICA_REGION", "settings": { "tier": "MACHINE_TYPE", } }
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"
First, check that the value of the max_connections
flag is greater than or equal to the value on the primary.
If the max_connections
flag is set appropriately, inspect the logs in Cloud Logging to find the actual error.
If the error is: set Service Networking service account as servicenetworking.serviceAgent role on consumer project
, then disable and re-enable the Service Networking API
. This action creates the service account necessary to continue with the process.
Restart the replica instance to reclaim the temporary memory space.
Replication stopped. The maximum storage limit was reached and automatic storage increase isn't enabled. Edit the instance to enable automatic storage increase
.
DELETE ... WHERE field < 50000000
cause replication lag with row-based replication since a huge number of updates are piled up on the replica.Some possible solutions include:
Recreate the replica after stopping all running queries.
What's nextExcept as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-02 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4