This page describes how to create a read replica for a Cloud SQL instance.
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 begin
If you are creating the first replica for this instance, ensure that the instance meets the requirements for primary instances. Learn more.
Create a read replica
You can create a maximum of 8 read replicas per primary instance.The steps for creating a read replica are below.
Console
-
In the Google Cloud Console, go to the Cloud SQL Instances page.
- Find the instance you want to create a replica for, and open its more
actions menu at the far right of its listing.

- Select Create read replica.
If you do not see that choice, the instance is a replica; you cannot create a replica of a replica.
- Click Create.
You are returned to the instance page for the master.
gcloud
Create the replica:
gcloud sql instances create REPLICA_NAME \ --master-instance-name=MASTER_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 a private IP address only, add the
--no-assign-ip parameter to the command.
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, the replica is
created in a random range.
REST v1beta4
Use 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:
- project-id: The project ID
- database-version: Enum version string (for example, SQLSERVER_2017_ENTERPRISE)
- primary-instance-name: The name of the primary instance
- primary-instance-region: The region of the primary instance
- replica-region: The region of the replica instance
- replica-name: The name of the replica instance
- machine-type: Enum string of the machine type. For example: "db-custom-1-3840"
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:
You should receive a JSON response similar to the following:
Troubleshoot
| Issue | Troubleshooting |
|---|---|
| Read replica did not start replicating on creation. | There's probably a more specific error in the log files. Inspect the logs in Cloud Logging to find the actual error. |
| Unable to create read replica - invalidFlagValue error. | One of the flags in the request is invalid. It could be a flag you
provided explicitly or one that was set to a default value.
First, check that the value of the If the |
| Unable to create read replica - unknown error. | There's probably a more specific error in the log files.
Inspect the logs in
Cloud Logging to find the actual error.
If the error is: |
| Disk is full. | The primary instance disk size can become full during replica creation. Edit the primary instance to upgrade it to a larger disk size. |
| The replica instance is using too much memory. | The replica uses temporary memory to cache often-requested read
operations, which can lead it to use more memory than the primary instance.
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 |
| Replication lag is consistently high. | The write load is too high for the replica to handle. Replication lag
takes place when the SQL thread on a replica is unable to keep up with the
IO thread. Some kinds of queries or workloads can cause temporary or
permanent high replication lag for a given schema. Some of the typical
causes of replication lag are:
Some possible solutions include:
|
| Replica creation fails with timeout. | Long-running uncommitted transactions on the primary instance can cause
read replica creation to fail.
Recreate the replica after stopping all running queries. |
What's next
- Learn how to manage replicas.
- Learn about cross-region replicas.