Managing Read Replicas

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.

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

  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.

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.

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.

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 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

  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.

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 PostgreSQL