This page describes how you can disable and enable replication for a read replica, as well as how to promote a replica to a stand-alone instance or delete it. For information about working with read replicas, see Requirements and Tips for Configuring Replication.
Disabling replication
By default, a replica starts with replication enabled. However, you can disable replication, for example, to debug or analyze the state of an instance. When you are ready, you explicitly reenable replication. Disabling or reenabling replication restarts the replica.
Disabling replication does not stop the replica instance; it becomes a read-only instance that is no longer replicating from its master instance. You continue to be charged for the instance. You can reenable replication on the disabled replica, delete the replica, or promote the replica to a stand-alone instance. You cannot stop the replica.
To disable replication:
Console
- Go to the Cloud SQL Instances page in the Google Cloud Platform Console.
- Open a replica instance by clicking its name.
- Click Disable replication in the button bar.
- Click OK.
gcloud
gcloud sql instances patch [REPLICA_NAME] --no-enable-database-replication
cURL
To execute this cURL command at a command line prompt, you acquire an access token by using the gcloud auth application-default print-access-token command. You can also use the APIs Explorer on the Instances:patch page to send the REST API request.
ACCESS_TOKEN="$(gcloud auth application-default print-access-token)" curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \ --header 'Content-Type: application/json' \ --data '{"settings": {"databaseReplicationEnabled" : "False" }}' \ -X PATCH \ https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[REPLICA_NAME]
Enabling replication
If a replica has not been replicating for a long time, it will take longer for it to catch up to the master. In this case, you should delete the replica and create a new one.
To enable replication:
Console
- Go to the Cloud SQL Instances page in the Google Cloud Platform Console.
- Select a replica instance by clicking its name.
- Click Enable replication in the button bar.
- Click OK.
gcloud
gcloud sql instances patch [REPLICA_NAME] --enable-database-replication
cURL
To execute this cURL command at a command line prompt, you acquire an access token by using the gcloud auth application-default print-access-token command. You can also use the APIs Explorer on the Instances:patch page to send the REST API request.
ACCESS_TOKEN="$(gcloud auth application-default print-access-token)" curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \ --header 'Content-Type: application/json' \ --data '{"settings": {"databaseReplicationEnabled" : "True" }}' \ -X PATCH \ https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[REPLICA_NAME]
Promoting a replica
Promoting a replica to a stand-alone Cloud SQL instance is an irreversible action. Once promoted, an instance cannot be converted back to a read replica.
To promote a replica to a stand-alone instance:
Console
- Go to the Cloud SQL Instances page in the Google Cloud Platform Console.
- Select a replica instance by clicking its name.
- Click Promote replica in the button bar.
- Click OK.
gcloud
gcloud sql instances promote-replica [REPLICA_NAME]
cURL
To execute this cURL command at a command line prompt, you acquire an access token by using the gcloud auth application-default print-access-token command. You can also use the APIs Explorer on the Instances:promoteReplica page to send the REST API request.
ACCESS_TOKEN="$(gcloud auth application-default print-access-token)" curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \ --header 'Content-Length: 0' \ -X POST \ https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[REPLICA_NAME]/promoteReplica
Confirm that the promoted instance is configured correctly. In particular, you should enable automated backups and consider configuring the instance for high availability if needed.
Checking replication status
When you log into an individual
replica instance using an administration client, you get details about
replication, including status and metrics. When you use the Google Cloud Platform Console or
the gcloud
command-line tool, you get a brief summary of replication.
To check replication status:
Console
- Go to the Cloud SQL Instances page in the Google Cloud Platform Console.
- Select a replica instance by clicking its name.
- The replication status is provided in a banner at the top of the page.
gcloud
For a replica instance, check the replication status with:
gcloud sql instances describe [REPLICA_NAME]
In the output, look for the properties databaseReplicationEnabled
and
masterInstanceName
.
For a master instance, check if there are replicas with:
gcloud sql instances describe [MASTER_INSTANCE_NAME]
In the output, look for the property replicaNames
.
MySQL Client
- Connect to the replica with a MySQL client.
For information, see Connection Options for External Applications.
- Check the replica's status:
SHOW SLAVE STATUS \G
- Look for the following metrics in the output of the command:
Master_Host
: The name of the master instance.Slave_IO_Running
: Indicates whether the I/O thread for reading the master's binary log is running. It should beYes
when replication is started.Slave_SQL_Running
: Indicates whether the SQL thread for executing events in the relay log is running. It should beYes
when replication is started.Seconds_Behind_Master
: The number of seconds that the slave SQL thread is behind processing the master binary log. It should beO
or a small number of seconds.
For more details about the output from the command, see Checking Replication Status.
What's next
- Learn how to create a read replica.
- Learn how to configure an external replica configuration.
- Learn how to configure an external master configuration.
- Learn more about requirements and best practices for replication.