This page describes how to manage read replicas. These operations include disabling and enabling replication, promoting a replica, configuring parallel replication, and checking the replication status. Show For more information about how replication works, see Replication in Cloud SQL. Disable replicationBy 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 re-enable replication. Disabling or re-enabling replication doesn't restart the replica instance. Disabling replication does not stop the replica instance; it becomes a read-only instance that is no longer replicating from its primary instance. You continue to be charged for the instance. On the disabled replica, you can re-enable replication, delete the replica, or promote the replica to a stand-alone instance. To disable replication: In the Google Cloud console, go to the Cloud SQL Instances page. Go to Cloud SQL Instances To execute this cURL command at a command line prompt, you acquire an access token by using the gcloud auth print-access-token command. You can also use the
APIs Explorer on the Instances:patch page to send the REST API request. Before using any of the request data, make the following replacements: HTTP method and URL: Request JSON body: To send your request, expand one of these options: Save the request body in a file called Save the request body in a file called Invoke-WebRequest ` You should receive a JSON response similar to the following: To execute this cURL command at a command line prompt, you acquire an access token by using the
gcloud auth print-access-token command. You can also use the APIs Explorer on the Instances:patch page to send the REST API request. Before using any of the request data, make the following replacements: HTTP method and URL: Request JSON body: To send your request, expand one of these options: Save the request body in a file called curl -X PATCH \ PowerShell (Windows) Save the request body in a file called $cred = gcloud auth print-access-token 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/replica-name", "status": "PENDING", "user": "", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "UPDATE", "name": "operation-id", "targetId": "replica-name", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id", "targetProject": "project-id" } Enable replicationIf a replica has not been replicating for a long time, it will take longer for it to catch up to the primary instance. In this case, delete the replica and create a new one. To enable replication: In the Google Cloud console, go to the Cloud SQL Instances page. Go to
Cloud SQL Instances To execute this cURL command at a command line prompt, you acquire an access token by using the
gcloud auth print-access-token command. You can also use the APIs Explorer on the Instances:patch page to send the REST API request. Before using any of the request data, make the following replacements: HTTP method and URL: Request JSON body: To send your request, expand one of these options: Save the request body in a file called Save the request body in a file called Invoke-WebRequest ` You should receive a JSON response similar to the following: To
execute this cURL command at a command line prompt, you acquire an access token by using the gcloud auth print-access-token command. You can also use the APIs Explorer on the Instances:patch page to send the REST API request. Before using any of the request
data, make the following replacements: HTTP method and URL: Request JSON body: To send your request, expand one of these options: curl (Linux, macOS, or Cloud Shell) Save the request body in a file called curl -X PATCH \ PowerShell (Windows) Save the request body in a file called $cred = gcloud auth print-access-token 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/replica-name", "status": "PENDING", "user": "", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "UPDATE", "name": "operation-id", "targetId": "replica-name", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id", "targetProject": "project-id" } Promoting a read replica stops replication and converts the instance to a standalone Cloud SQL primary instance with read and write capabilities. When promoted, read replicas are automatically configured with backups, but they aren't automatically configured as high availability (HA) instances. You can enable high availability after promoting the replica just as you would for any non-replica instance. Configuring a read replica for high availability is done the same way as for a primary instance. Learn more about configuring the instance for high availability. Before promoting a read replica, if the primary is still available and serving clients, you should do the following:
Otherwise, a newly promoted instance may be missing some transactions that were committed to the primary instance. To promote a replica to a standalone instance: Confirm that the promoted instance is configured correctly. In particular, consider configuring the instance for high availability if needed. Configure parallel replicationReducing replication lag is important for managing replication performance. Replication lag occurs when the updates to a read replica fall behind the updates to the primary instance. This section describes how users can enable parallel replication, which can reduce replication lag. In MySQL replication, a replication SQL thread is used to execute the transactions that are collected in the relay log on the read replica. Parallel replication reduces replication lag by increasing the number of SQL threads that work to execute these transactions. Read replicas with parallel replication enabled are sometimes called multithreaded replicas. Parallel replication is available in these three scenarios in Cloud SQL for MySQL:
For simplicity, this page uses the terms "primary instance" and "read replica." Basic steps to change parallel replication flagsThe steps for enabling parallel replication are the following:
Read replicas: Flags for parallel replicationCloud SQL for MySQL supports several flags for parallel replication on read replicas. For information about the flags, click these links to the MySQL 8.0 documentation:
Changing these flags does not restart the read replica. The following table contains the allowed ranges and default values for these flags:
The The
The Primary instance: Flags for parallel replicationCloud SQL for MySQL supports several flags for use on a primary instance. You can use these flags to tune replication performance for associated read replicas with parallel replication enabled. For information about the flags, click these links to the MySQL 8.0 documentation:
Changing these flags does not restart the primary instance. The following table contains the allowed ranges and default values for these flags:
In MySQL 5.7, if Check replication statusWhen you view a replica instance using the Google Cloud console or log into the instance using an administration client, you get details about replication, including status and metrics. When you use the gcloud, you get a brief summary of the replication configuration. Before checking the replication status for a Cloud SQL replica instance, use the The following metrics are available for replica instances. (Learn more about additional metrics available for all instances, including non-replica instances.)
To check replication status: Cloud SQL reports the To view other metrics for in-region and cross-region replicas, and replicas of external
servers, create a custom dashboard and add the metrics you wish to monitor to it: In the Google Cloud console, go to the Monitoring page. Go to Monitoring
gcloudFor a replica instance, check the replication status with: gcloud sql instances describe REPLICA_NAME In the output, look for the properties For a primary instance, check if there are replicas with: gcloud sql instances describe PRIMARY_INSTANCE_NAME In the output, look for the property mysql Client
For more details about the output from this command, see the MySQL documentation on Checking Replication Status. Troubleshoot
What's next
|