After you create an external server HA replica, you cannot change it to a non-HA replica. This is true conversely as well. You cannot change an external server non-HA replica to an HA replica.
Manual failover might lead to unrecoverable migration if attempted when the instance is still loading the initial data, or to temporary downtime if the instance is already replicating from the source. Check the replication status.
POSTGRES_9_6
, POSTGRES_10
, POSTGRES_11
, POSTGRES_12
, POSTGRES_13
, POSTGRES_14
, POSTGRES_15
, POSTGRES_16
, or POSTGRES_17
. Match the database version running on your external server, or set the value to no more than one version later.Before you start this step, create a JSON file that contains your replica request data. Then, to create a Cloud SQL replica, open a Cloud Shell terminal and run these commands:
gcloudauthlogin ACCESS_TOKEN="$(gcloudauthprint-access-token)"curl--header"Authorization: Bearer ${ACCESS_TOKEN}"\--header'Content-Type: application/json'\--data@JSON_PATH\-XPOST\https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT-ID/instances
gcloudauthlogin ACCESS_TOKEN="$(gcloudauthprint-access-token)"curl--header"Authorization: Bearer ${ACCESS_TOKEN}"\--header'Content-Type: application/json'\--data@./replica.json\-XPOST\https://sqladmin.googleapis.com/sql/v1beta4/projects/MyProject/instances
Property | Description |
---|---|
PROJECT_ID | The ID of your project in Google Cloud, which must be the same as that of the source instance. |
JSON_PATH | The path to the JSON file that contains the request data for the Cloud SQL replica. |
To ensure your instances were set up correctly, go to the Cloud SQL Instances page.
You should see your source representation instance and the Cloud SQL replica, in a listing similar to the following:
Instance ID | Type | Public IP |
---|---|---|
(-) source-representation-instance | Database external primary | 10.68.48.3:5432 |
replica-instance | Database read replica | 34.66.48.59 |
Also make sure that you have the cloudsql.instances.migrate
permission on the Cloud SQL replica. This permission is included in the cloudsql.admin
or cloudsql.editor
IAM roles.
You cannot import database user accounts from the external server, but you can create them on a Cloud SQL replica. Do this before you replicate from the external server.
You can use the outgoing IP address of the Cloud SQL replica to create a secure connection between the external server and the Cloud SQL replica. You won't be charged for this IP address.
To get the outgoing IP address for the replica, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
Next to the Cloud SQL replica's public IP address, hold the pointer over the More info tooltip and retrieve the outgoing IP address.
Note that the outgoing IP address is not the IP address displayed in the main listing for the replica in the Google Cloud console.
To get the outgoing IP address for the replica, run the following command:
gcloudsqlinstancesdescribeREPLICA_NAME--format="default(ipAddresses)"
Property | Description |
---|---|
REPLICA_NAME | The name of the Cloud SQL replica whose outgoing public IP address you want to retrieve. |
The Cloud SQL replica needs to connect to the external server for replication to succeed. You must configure the network firewall for your external server to accept connections from the Cloud SQL replica's outgoing IP address if the following conditions apply:
To connect to the Cloud SQL replica, you use the replica's primary IP address. This IP address is displayed in the Google Cloud console.
After you set up the source representation instance for the Cloud SQL replica, you might need to update the source representation instance. For example, these scenarios require an update to your configurations:
For the initial loading of data from the external server into the Cloud SQL replica, use a managed import. It uses a service that extracts data from the external server and imports it into the Cloud SQL instance directly. For more information, see Using a managed import to set up replication from external databases.
When the Cloud SQL replica finishes the initial data load, it connects to the external server and applies all updates that were made after the export operation. Confirm your replication status.
It's important to check the replication status before promoting the replica to a standalone instance. If the replication process isn't successfully completed, a promoted replica doesn't have all the changes from your external server.
If replication delay is not trending toward 0, take steps to address it. You might want to check these metrics: /postgresql/external_sync/initial_sync_complete
, postgresql/external_sync/max_replica_byte_lag
, and database/replication/state
. View the list of Cloud SQL metrics.
If you want to migrate a subset of databases from the source representation instance to the destination Cloud SQL instance, then check the following per-database metrics:
Metric | Description |
---|---|
per_database/postgresql/external_sync/initial_sync_complete | Understand the migration phase of a database. If the value for this metric is 0 , then the database is still part of the initial data dump. If the value is 1 , then the database has completed the initial data dump and is in the change data capture (CDC) phase. |
per_database/postgresql/external_sync/replication_byte_lag | Know the replication lag for a database (in bytes). |
After the Cloud SQL replica has caught up with the external server and there's no replication delay on the Cloud SQL replica, connect to your database. Run the appropriate database commands to make sure that the contents are as expected when compared with the external server. Retain your external server until the necessary validations are done.
After migration, you can create cascading read replicas under your Cloud SQL replica before promoting the Cloud SQL replica.
To create a cascading replica, run the following commands:
In the Google Cloud console, go to the Cloud SQL Instances page.
Cloud SQL creates a replica. You're returned to the instance page for the parent replica.
--master-instance-name
flag:gcloudsqlinstancescreateREPLICA_NAME\--master-instance-name=PARENT_REPLICA_NAME\
After the replica is created, you can see that the changes made to the primary instance are replicated through all the replicas in the cascading replicas chain.
request.json
: {"masterInstanceName":"EXTERNAL_SERVER_REPLICA_NAME", "project":"PROJECT_ID", "name":"REPLICA_NAME", "region":"REPLICA_REGION", "settings": {"tier":"MACHINE_TYPE", }}
curl-XPOST -H"Authorization: Bearer "$(gcloudauthprint-access-token) -H"Content-Type: application/json; charset=utf-8" -d@request.json "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances"
Promote your replica by following these steps:
AVAILABILITY_TYPE
to REGIONAL
.If you install extensions on your external source databases that Cloud SQL doesn't support, then when you migrate the databases to a destination instance, Cloud SQL won't migrate these extensions. To ensure a smooth migration, verify that no objects or applications reference the extensions. Before proceeding with the migration, we recommend removing the extensions along with any references from the source databases.
For more information about the extensions that Cloud SQL supports, see Configure PostgreSQL extensions.
If you install the pg_cron
extension on your external source databases, then when you migrate the databases to a destination instance, Cloud SQL doesn't migrate the extension or any cron
settings associated with the extension. After you migrate the databases and promote the replica, Google recommends that you re-enable the pg_cron
extension on each migrated database.
You can't migrate data from version 11 of a source Microsoft Azure server to version 11 of a destination Cloud SQL for PostgreSQL instance. To resolve this, migrate the data to a Cloud SQL instance that has a version of 12 or later.
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-04-17 UTC.