Stay organized with collections Save and categorize content based on your preferences.
This page describes how to use advanced disaster recovery (DR). Advanced DR provides two main capabilities:
Advanced DR is supported only on Cloud SQL Enterprise Plus edition instances.
Note: This page contains features related to Cloud SQL editions. For more information about Cloud SQL editions, see Introduction to Cloud SQL editions. Before you beginIf you plan to use the Google Cloud SDK, then you must use version 502.0.0 or later. To check the version of the Google Cloud SDK, run gcloud --version
. To update the Google Cloud SDK, run gcloud components update
.
To install the Google Cloud SDK, see Install the gcloud CLI.
Designate a DR replicaTo perform advanced DR, you must first designate a cross-region DR replica.
Primary instance requirementsThe primary instance must be a Cloud SQL Enterprise Plus edition instance and have a designated DR replica.
You must enable point-in-time recovery (PITR) on the primary instance. To enable PITR, see
Use point-in-time recovery (PITR).
If you're creating your Cloud SQL instance with a DNS write endpoint, then your primary instance must have the same SSL configuration as the designated DR replica before you invoke the switchover or replica failover operation. For example, if you configure your DR replica to enforce SSL encryption, but the primary instance allows unencrypted connections, then clients won't be able to connect to the new primary instance after the switchover or failover operation completes.
DR replica requirementsThe designated DR read replica must meet the following requirements:
Must be in a separate region from the primary instance
Must be a direct read replica; can't be a cascading replica
If configured with a flag that requires the replica to have a greater or equal value than the primary instance, then the flag must be configured with a value equal to the primary instance. Note that depending on the machine type (tier) and instance size of the DR replica, the default values can be different even if you have not set them explicitly. These flags are the following:
max_connections
max_worker_processes
max_wal_senders
max_prepared_transactions
max_parallel_workers
max_locks_per_transaction
max_parallel_maintenance_workers
max_parallel_workers_per_gather
Can't have the cloudsql.logical_decoding
flag configured; can't have any logical slots or logical replication configured
Must store the transaction logs used for PITR in Cloud Storage
Can't be an external replica
This section provides recommendations for your DR replica. The following recommendations can help you avoid performance issues in your deployment:
If the primary instance doesn't already have a cross-region read replica that satisfies the DR replica requirements, then create one.
ConsoleIn the Google Cloud console, go to the Cloud SQL Instances page.
Cloud SQL creates a backup of the primary instance and creates the replica. You are returned to the instance page for the primary.
gcloudTo create a replica that meets the requirements of a DR replica, run the following command:
gcloud sql instances create REPLICA_NAME \ --master-instance-name=PRIMARY_INSTANCE_NAME \ --region=REPLICA_REGION_NAME \ --database-version=DATABASE_VERSION \ --tier=MACHINE_TYPE \ --availability-type=AVAILABILITY_TYPE --edition="ENTERPRISE_PLUS"
Replace the following variables:
POSTGRES_16
.
The database major and minor versions must be the same for both the primary and DR replica.
REGIONAL
to enable high availability.ENTERPRISE_PLUS
.To create a DR replica, use a Terraform resource.
REST v1Before using any of the request data, make the following replacements:
POSTGRES_16
. The database version must be the same for both the primary and DR replica.REGIONAL
to enable high availability.HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/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", "availabilityType": "AVAILABILITY_TYPE", "settingsVersion": 0, "replicationType": "ASYNCHRONOUS", } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID", "status": "PENDING", "user": "user@example.com", "insertTime": "2024-04-01T22:43:37.981Z", "operationType": "CREATE_REPLICA", "name": "OPERATION_ID", "targetId": "INSTANCE_ID", "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }REST v1beta4
Before using any of the request data, make the following replacements:
POSTGRES_16
. The database version must be the same for both the primary and DR replica.REGIONAL
to enable high availability.HTTP method and URL:
POST https://sqladmin.googleapis.com/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", "availabilityType": "AVAILABILITY_TYPE", "settingsVersion": 0, "replicationType": "ASYNCHRONOUS", } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID", "status": "PENDING", "user": "user@example.com", "insertTime": "2024-04-01T22:43:37.981Z", "operationType": "CREATE_REPLICA", "name": "OPERATION_ID", "targetId": "INSTANCE_ID", "selfLink": "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_UD/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }Designate the DR replica for the primary instance
The following procedures describe how to designate one of the cross-region replicas of a primary instance as a DR replica for switchover or replica failover.
ConsoleTo designate a DR replica for a primary instance, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
To designate a DR replica for a primary instance, use the following command:
gcloud sql instances patch PRIMARY_INSTANCE_NAME \ --failover-dr-replica-name=REPLICA_NAME
Replace the following variables:
To designate a DR replica for a primary instance, use a Terraform resource.
REST v1Before using any of the request data, make the following replacements:
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME
Request JSON body:
{ "replicationCluster": { "failoverDrReplicaName": "REPLICA_NAME" } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X PATCH \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/instances/INSTANCE_ID", "status": "PENDING", "user": "user@example.com", "insertTime": "2024-04-01T21:30:35.667Z", "operationType": "UPDATE", "name": "OPERATION_ID", "targetId": "INSTANCE_ID", "selfLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }REST v1beta4
Before using any of the request data, make the following replacements:
HTTP method and URL:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME
Request JSON body:
{ "replicationCluster": { "failoverDrReplicaName": "REPLICA_NAME" } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X PATCH \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME" | Select-Object -Expand Content
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/INSTANCE_ID", "status": "PENDING", "user": "user@example.com", "insertTime": "2024-04-01T21:30:35.667Z", "operationType": "UPDATE", "name": "OPERATION_ID", "targetId": "INSTANCE_ID", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }Change the DR replica designation
If the replica meets the requirements, then you can designate a different replica as the DR replica. The old DR replica loses the DR replica designation.
ConsoleTo change the DR replica for a primary instance, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
To change the DR replica, run the designate command again, and specify a different DR replica.
RESTTo change the DR replica, make the designate API request again, and specify a different DR replica.
View the DR replica designationYou can check which DR replica is assigned to the primary instance by using the gcloud CLI or the Cloud SQL Admin API. You can also check whether a replica is a designated DR replica.
To find out which DR replica is designated for a primary instance, use the following procedure.
ConsoleTo find out which read replica is the designated DR replica for a primary instance, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
PostgreSQL disaster recovery replica
appears in the Type column for the designated DR replica.To find out which instance is the designated DR replica of a primary instance, use the following command:
gcloud sql instances describe PRIMARY_INSTANCE_NAME
Replace the following variable:
The output of this command contains the field named failoverDrReplica
which identifies the designated DR replica.
Before using any of the request data, make the following replacements:
HTTP method and URL:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Execute the following command:
curl -X GET \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#instance", "state": "RUNNABLE", "databaseVersion": "POSTGRES_16", "settings": { . . . "replicaNames": [ "my-instance-replica" ], "ipAddresses": [ { "type": "PRIMARY", "ipAddress": "192.5.4.1" } ], "instanceType": "CLOUD_SQL_INSTANCE", . . . "connectionName": "my-project:us-east1:my-instance", "name": "my-instance", "region": "us-east1", "gceZone": "us-east1-c", "secondaryGceZone": "us-east1-b", "databaseInstalledVersion": "POSTGRES_16", "maintenanceVersion": "POSTGRES_16_3.R20240205.00_07", "replicationCluster" { "failoverDrReplicaName": "my-project:my-instance-replica" }, "createTime": "2024-03-15T18:11:03.596Z", "sqlNetworkArchitecture": "NEW_NETWORK_ARCHITECTURE" } }REST v1beta4
Before using any of the request data, make the following replacements:
HTTP method and URL:
GET https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Execute the following command:
curl -X GET \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1beta4/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#instance", "state": "RUNNABLE", "databaseVersion": "POSTGRES_16", "settings": { . . . "replicaNames": [ "my-instance-replica" ], "ipAddresses": [ { "type": "PRIMARY", "ipAddress": "192.5.4.1" } ], "instanceType": "CLOUD_SQL_INSTANCE", . . . "connectionName": "my-project:us-east1:my-instance", "name": "my-instance", "region": "us-east1", "gceZone": "us-east1-c", "secondaryGceZone": "us-east1-b", "databaseInstalledVersion": "POSTGRES_16", "maintenanceVersion": "POSTGRES_16_3.R20240205.00_07", "replicationCluster" { "failoverDrReplicaName": "my-project:my-instance-replica" }, "createTime": "2024-03-15T18:11:03.596Z", "sqlNetworkArchitecture": "NEW_NETWORK_ARCHITECTURE" } }
To check whether a replica is a DR replica, use one of the following procedures.
ConsoleTo check whether a replica instance is a DR replica, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
PostgreSQL disaster recovery replica
appears in the Type column for the designated DR replica.To check whether a replica instance is a DR replica, run the following command:
gcloud sql instances describe REPLICA_NAME
Replace the following variable:
If the replica is a DR replica, then the output of the command contains the field drReplica=true
.
Before using any of the request data, make the following replacements:
HTTP method and URL:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_NAME
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Execute the following command:
curl -X GET \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_NAME"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_NAME" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#instance", "state": "RUNNABLE", "databaseVersion": "POSTGRES_16", "settings": { "authorizedGaeApplications": [], "tier": "db-perf-optimized-N-8", "kind": "sql#settings", "availabilityType": "REGIONAL", "pricingPlan": "PER_USE", "replicationType": "SYNCHRONOUS", . . . }, "masterInstanceName": "my-project:my-instance", "ipAddresses": [ { "type": "PRIMARY", "ipAddress": "192.3.2.1" } ], . . . "instanceType": "READ_REPLICA_INSTANCE", . . . "connectionName": "my-project:us-east4:my-instance-replica", "name": "my-instance-replica", "region": "us-east4", "gceZone": "us-east4-b", "secondaryGceZone": "us-east4-c", "databaseInstalledVersion": "POSTGRES_16", "maintenanceVersion": "POSTGRES_16_3.R20240205.00_07", "replicationCluster" { "drReplica": true }, "createTime": "2024-03-15T18:17:44.655Z", "sqlNetworkArchitecture": "NEW_NETWORK_ARCHITECTURE" }REST v1beta4
Before using any of the request data, make the following replacements:
HTTP method and URL:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_NAME
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Execute the following command:
curl -X GET \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_NAME"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_NAME" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#instance", "state": "RUNNABLE", "databaseVersion": "POSTGRES_16", "settings": { "authorizedGaeApplications": [], "tier": "db-perf-optimized-N-8", "kind": "sql#settings", "availabilityType": "REGIONAL", "pricingPlan": "PER_USE", "replicationType": "SYNCHRONOUS", . . . }, "masterInstanceName": "my-project:my-instance", "ipAddresses": [ { "type": "PRIMARY", "ipAddress": "192.3.2.1" } ], . . . "instanceType": "READ_REPLICA_INSTANCE", . . . "connectionName": "my-project:us-east4:my-instance-replica", "name": "my-instance-replica", "region": "us-east4", "gceZone": "us-east4-b", "secondaryGceZone": "us-east4-c", "databaseInstalledVersion": "POSTGRES_16", "maintenanceVersion": "POSTGRES_16_3.R20240205.00_07", "replicationCluster" { "drReplica": true }, "createTime": "2024-03-15T18:17:44.655Z", "sqlNetworkArchitecture": "NEW_NETWORK_ARCHITECTURE" }Remove the DR replica
You can clear the DR replica designation from a primary instance. However, if no DR replica is assigned to a primary instance, then you can't perform switchover or replica failover.
ConsoleTo remove a designated DR replica from a primary instance, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
To remove the DR replica designation, run the following command on the primary instance:
gcloud sql instances patch PRIMARY_INSTANCE_NAME \ --clear-failover-dr-replica-name
Replace the following variable:
Before using any of the request data, make the following replacements:
failoverDrReplicaName
field to an empty string.HTTP method and URL:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME
Request JSON body:
{ "replicationCluster": { "failoverDrReplicaName": "" } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X PATCH \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/instances/INSTANCE_ID", "status": "PENDING", "user": "user@example.com", "insertTime": "2024-04-01T21:30:35.667Z", "operationType": "UPDATE", "name": "OPERATION_ID", "targetId": "INSTANCE_ID", "selfLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }REST v1beta4
Before using any of the request data, make the following replacements:
failoverDrReplicaName
field to an empty string.HTTP method and URL:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME
Request JSON body:
{ "replicationCluster": { "failoverDrReplicaName": "" } }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
curl -X PATCH \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Save the request body in a file named request.json
, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/PRIMARY_INSTANCE_NAME" | Select-Object -Expand Content
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/INSTANCE_ID", "status": "PENDING", "user": "user@example.com", "insertTime": "2024-04-01T21:30:35.667Z", "operationType": "UPDATE", "name": "OPERATION_ID", "targetId": "INSTANCE_ID", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }Perform a switchover
After you've designated a DR replica, you can perform the switchover operation. However, as a best practice, avoid performing the switchover operation under the following circumstances:
To avoid a timeout, consider performing switchover when the transaction volume is low.
When switchover completes, the operation takes a backup of the new primary instance (the former DR replica) as soon as the new primary instance is promoted. After this backup is complete, then point-in-time-recovery (PITR) is fully enabled on the new primary instance. This backup can take between 5 and 15 minutes to complete depending on the disk size. PITR coverage starts only after this backup has completed. For more information about the considerations of using PITR with advanced DR, see Use PITR with advanced DR.
After the switchover operation is complete, you'll notice that the direction of replication is reversed.
After your old primary instance is reconfigured as a read replica, the DNS write endpoint, which previously resolved to the old primary instance, resolves to the new primary instance.
Important: If you're not using a DNS write endpoint, then you must point your applications to use the IP address of the new primary instance. Before you beginBefore you perform the switchover operation, do the following:
cloudsql.logical_decoding
flag configured. Neither instance can have logical slots or logical replication configured.To perform the switchover operation, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
To perform the switchover operation, run the following command:
gcloud sql instances switchover REPLICA_NAME [--db-timeout=TIMEOUT_DURATION ]
Replace the following variables:
If you don't specify this parameter, the switchover operation includes a timeout of 10 minutes.
You can increase the value of this timeout by specifying the --db-timeout
parameter. Replace TIMEOUT_DURATION with a time period duration of up to 24 hours, including an initial notation for the format. For example, for 30 seconds, specify 30s
. For 24 hours, specify 24h
. You can also specify fractional units of time period by using decimals up to 9 places. For example, for 30.5 minutes, specify 30.5m
.
If you don't have any pending operations, then you can decrease the value of this timeout.
To begin the switchover operation, use a Terraform resource. To make the DR replica the new primary instance, run the first sample.
If switchover completes successfully, when you run terraform apply
for the second sample, then a message similar to the following appears:
No changes. Your infrastructure matches the configuration.
Before using any of the request data, make the following replacements:
HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_NAME/switchover
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_NAME/switchover"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_NAME/switchover" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_NAME", "status": "PENDING", "user": "user@example.com", "insertTime": "2024-04-01T22:43:37.981Z", "operationType": "SWITCHOVER", "name": "OPERATION_ID", "targetId": "REPLICA_ID", "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }REST v1beta4
Before using any of the request data, make the following replacements:
HTTP method and URL:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_NAME/switchover
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_NAME/switchover"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_NAME/switchover" | Select-Object -Expand Content
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": "user@example.com", "insertTime": "2024-04-01T22:43:37.981Z", "operationType": "SWITCHOVER", "name": "OPERATION_ID", "targetId": "REPLICA_ID", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }Perform DR by invoking a replica failover
In the event of region failure or a disaster, you can perform DR by invoking a replica failover operation to your designated DR replica. To perform a replica failover, you promote the designated DR replica. In contrast with switchover, the promotion of the DR replica is immediate.
Since the DR replica assumes the role of the primary instance immediately, it's possible that the replica doesn't have all of the data from the old primary instance due to replication lag. For this reason, a replica failover can incur data loss.
As part of the promotion process, replica failover takes a backup of the new primary instance (the former DR replica) right after the DR replica becomes the new primary instance. After this backup is complete, point-in-time-recovery (PITR) is fully enabled on the new primary instance. This backup can take between 5 and 15 minutes to complete depending on the disk size of the new (and old) primary instance. During this backup period, PITR isn't available.
When the old primary instance comes back online, the replica failover process takes a backup. After this backup is taken, the old primary instance is recreated as a read replica of the new primary instance.
For more information about the considerations of using PITR with advanced DR, see Use PITR with advanced DR.
After you invoke the replica failover operation, the DNS write endpoint, which previously resolved to the old primary instance, resolves to the new primary instance.
Important: If you're not using a DNS write endpoint, then you must point your applications to use the IP address of the new primary instance. Before you beginBefore you can perform a replica failover, do the following:
cloudsql.logical_decoding
flag configured. Neither instance can have logical slots or logical replication configured. If you invoke replica failover and the original primary has logical decoding enabled, then when the original primary becomes a read replica, any logical slots configured on the original primary instance are lost.To perform the replica failover operation, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
To invoke a replica failover to the DR replica, use the following command:
gcloud sql instances promote-replica \ REPLICA_NAME --failover
Replace the following variable:
Before using any of the request data, make the following replacements:
true
to use replica failover. If you set to false
, then the API uses the regular promoteReplica
method without replica failover.HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_NAME/promoteReplica?failover=ENABLE_REPLICA_FAILOVER
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_NAME/promoteReplica?failover=ENABLE_REPLICA_FAILOVER"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_NAME/promoteReplica?failover=ENABLE_REPLICA_FAILOVER" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_NAME", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "PROMOTE_REPLICA", "name": "OPERATION_ID", "targetId": "REPLICA_NAME", "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }REST v1beta4
Before using any of the request data, make the following replacements:
true
to use replica failover. If you set to false
, then the API uses the regular promoteReplica
method without replica failover.HTTP method and URL:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_NAME/promoteReplica?failover=ENABLE_REPLICA_FAILOVER
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell) Note: The following command assumes that you have logged in to thegcloud
CLI with your user account by running gcloud init
or gcloud auth login
, or by using Cloud Shell, which automatically logs you into the gcloud
CLI . You can check the currently active account by running gcloud auth list
.
Execute the following command:
curl -X POST \PowerShell (Windows) Note: The following command assumes that you have logged in to the
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_NAME/promoteReplica?failover=ENABLE_REPLICA_FAILOVER"
gcloud
CLI with your user account by running gcloud init
or gcloud auth login
. You can check the currently active account by running gcloud auth list
.
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_NAME/promoteReplica?failover=ENABLE_REPLICA_FAILOVER" | Select-Object -Expand Content
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": "user@example.com", "insertTime": "2024-04-01T22:43:37.981Z", "operationType": "PROMOTE_REPLICA", "name": "OPERATION_ID", "targetId": "REPLICA_NAME", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID", "targetProject": "PROJECT_ID" }Check the status of a replica failover
Replica failover occurs in two phases. The first phase is the promotion of the DR replica. The second phase is the recreation of the old primary instance as a read replica.
To check the status of replica failover, check the status of each phase.
Check the status of the first phase.
ConsoleTo check if the DR replica has been promoted to a standalone instance, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
gcloud sql instances describe DR_REPLICA_NAME
Replace the following variable:
In the output, check that the following field appears and the replica has become a standalone Cloud SQL primary instance:
instanceType: CLOUD_SQL_INSTANCE
To verify the completion of the second phase, check the operations log on the instance for the message RECONFIGURE_OLD_PRIMARY
.
The appearance of this message depends on when the old primary instance returns online, which can take minutes or days in the event of a disaster.
For more information on how to check the operations logs on an instance, see View instance logs.
With both switchover and replica failover, as soon as the DR replica is promoted to a primary instance, the following changes occur to support backup and PITR:
A new backup is taken to support PITR on the new primary instance.
The transaction log retention policy is copied from the old primary instance to the new primary instance.
For both the backup configuration and transaction log retention policies, we recommend that you verify that the settings inherited from the old primary instance are correct for the new primary instance.
Start of PITR coverageAt the end of the switchover operation, Cloud SQL schedules automated backups and takes the first backup of the new primary instance. If you want PITR coverage to begin sooner than later, then we recommend that you verify that the first backup is successful. The newly promoted primary instance has PITR coverage only after the first automated backup has completed successfully.
For more information about how to view the backups that are available for an instance, see View a list of backups.
PITR coverage for instances during switchover and replica failoverWhen an instance participates in a switchover or a replica failover operation, the instance spends time as a read replica. PITR and restoring a backup are supported during the time period that the instance spends as a read replica and as a primary instance.
You can perform PITR to a time before the switchover when the instance was a primary instance. For both switchover and replica failover operations, Cloud SQL initiates a best-effort backup for the new primary instance as soon as the new primary instance is promoted. PITR is enabled on the promoted instance only after this backup is completed. This backup can take 5 to 15 minutes to complete depending on the disk size.
Split-brain during replica failoverIt's possible that split-brain occurs when the primary instance continues to accept writes while a replica is promoted using replica failover. After the replica is promoted, when the old primary instance is available again, it is rebuilt as a replica of the promoted instance and a final backup is made. This backup can be used to recover any split-brain data that was not written to the promoted replica.
Note: Split-brain can't happen for switchover operations. Deletion of backups and transaction logs on replicasIf a primary instance that was enabled with PITR and backups becomes a read replica, then the last backup and PITR retention policy from its time as a primary instance is preserved and applied during its time as a replica. Even though the new primary instance is not taking backups, the old backups and transaction logs used for PITR are deleted on the read replica according to the last configured policy.
For example, if the instance is configured to have daily automated backups and keep 7 backups with 7 days of PITR logs, then when this instance becomes a read replica, anything older than 7 days is deleted once a day.
If you need to delete backups sooner, then you can remove backups manually. For more information, see Delete a backup.
Note: You can't modify backup configuration settings while the instance is a replica. LimitationsYou can't designate a Cloud SQL Enterprise Plus edition read replica instance as DR replica if the primary instance stores its transaction logs for point-in-time recovery (PITR) on disk. To check where an instance stores its logs for PITR, see Check the storage location of transaction logs used for PITR.
You can't designate an external replica as a DR replica.
Terraform isn't supported for replica failover operations.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4