Managing Replicas

This page describes how you can disable and enable replication for a replica, as well as how to promote a replica to a stand-alone instance or delete it.

Disabling replication

By default, a replica starts with replication enabled. However, you can disable replication when you need to, 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

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Open a replica instance by clicking its name.
  3. In the replica instance's Overview pane, click Disable replication.
  4. In the Disable replication dialog, 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

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Select a replica instance by clicking its name.
  3. In the replica instance's Overview pane, click Enable replication.
  4. In the Enable replication dialog, 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

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Select a replica instance by clicking its name.
  3. In the replica instance's Overview pane, click Promote replica.
  4. Click OK to promote the replica instance.

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

Checking replication status

When you log into an individual replica instance using MySQL client (or another MySQL administration tool), 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

  1. Go to the Cloud SQL Instances page in the Google Cloud Platform Console.

    Go to the Cloud SQL Instances page

  2. Select a replica instance by clicking its name.
  3. In the replica instance Overview pane, under Properties, find the Replication enabled field.

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

  1. Connect to the replica with a MySQL client.

    For information, see Connection Options for External Applications.

  2. Check the replica's status:
    SHOW SLAVE STATUS \G
  3. 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 be Yes when replication is started.
    • Slave_SQL_Running: Indicates whether the SQL thread for executing events in the relay log is running. It should be Yes 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 be O or a small number of seconds.

    For more details about the output from the command, see Checking Replication Status.

What's next

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud SQL for MySQL