如果错误为 set Service Networking service account as
servicenetworking.serviceAgent role on consumer project,则停用 Service
Networking API,然后重新启用。此操作会创建继续执行该过程所需的服务账号。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-19。"],[],[],null,["# Use a managed import to set up replication from external databases\n\n\u003cbr /\u003e\n\n[MySQL](/sql/docs/mysql/replication/managed-import-replication-from-external \"View this page for the MySQL database engine\") \\| PostgreSQL \\| SQL Server\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis page describes how to set up and use a managed import for data when\nreplicating from an external server to Cloud SQL.\n\nYou must complete all the steps on this page. When finished, you can\nadminister and monitor the source representation instance the same way as you\nwould any other Cloud SQL instance.\n\nBefore you begin\n----------------\n\nBefore you begin, complete these steps:\n\n1. [Configure the external server](/sql/docs/postgres/replication/configure-replication-from-external#setting_up_the_external_server_for_replication).\n\n2. [Create the source representation instance](/sql/docs/postgres/replication/configure-replication-from-external#setup-source-instance).\n\n3. [Set up the Cloud SQL replica](/sql/docs/postgres/replication/configure-replication-from-external#setup-replica-instance).\n\nVerify your replication settings\n--------------------------------\n\nAfter your setup is complete, ensure that the Cloud SQL replica\ncan replicate from the external server.\n\nThe following external sync settings must be correct.\n\n- Connectivity between the Cloud SQL replica and external server\n- Replication user privileges\n- Version compatibility\n- The Cloud SQL replica is not already replicating\n\nTo verify these settings, open a Cloud Shell terminal and enter the following\ncommands: \n\n### curl\n\n gcloud auth login\n ACCESS_TOKEN=\"$(gcloud auth print-access-token)\"\n curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header 'Content-Type: application/json' \\\n --data '{\n \"syncMode\": \"\u003cvar translate=\"no\"\u003eSYNC_MODE\u003c/var\u003e\",\n \"syncParallelLevel\": \"\u003cvar translate=\"no\"\u003eSYNC_PARALLEL_LEVEL\u003c/var\u003e\",\n \"selectedObjects\": \"\u003cvar translate=\"no\"\u003eSELECTED_OBJECTS\u003c/var\u003e\"\n }' \\\n -X POST \\\n https://sqladmin.googleapis.com/sql/v1beta4/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/instances/\u003cvar translate=\"no\"\u003eREPLICA_INSTANCE_ID\u003c/var\u003e/verifyExternalSyncSettings\n\n### example\n\n gcloud auth login\n ACCESS_TOKEN=\"$(gcloud auth print-access-token)\"\n curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header 'Content-Type: application/json' \\\n --data '{\n \"syncMode\": \"online\",\n \"syncParallelLevel\": \"optimal\",\n \"selectedObjects\":[{\"database\":\"db1\"}, {\"database\":\"db2\"}]\n }' \\\n -X POST \\\n https://sqladmin.googleapis.com/sql/v1beta4/projects/myproject/instances/myreplica/verifyExternalSyncSettings\n\nThese calls return a list of type `sql#externalSyncSettingErrorList`.\n\nIf the list is empty, then there are no errors. A response without errors appears like this: \n\n```bash\n {\n \"kind\": \"sql#externalSyncSettingErrorList\"\n }\n```\n\nUpdate a source representation instance\n---------------------------------------\n\nTo update the databases that you want to migrate from the source representation\ninstance to the destination Cloud SQL instance, update the list of\ndatabase names that are associated with the `selectedObjects` parameter. If you\ndon't use this parameter or provide an empty list as the value for the parameter,\nthen all databases are migrated from the source to the destination. \n\n### source.json\n\n\n```bash\n {\n \"name\": \"\u003cvar translate=\"no\"\u003eSOURCE_NAME\u003c/var\u003e\",\n \"region\": \"\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e\",\n \"databaseVersion\": \"\u003cvar translate=\"no\"\u003eDATABASE_VERSION\u003c/var\u003e\",\n \"onPremisesConfiguration\": {\n \"selectedObjects\": \"\u003cvar translate=\"no\"\u003eSELECTED_OBJECTS\u003c/var\u003e\",\n \"username\": \"\u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e\",\n \"password\": \"\u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e\"\n }\n }\n```\n\n\u003cbr /\u003e\n\n### example\n\n // example of source.json for external server that\n // - initiates replication from a Cloud SQL managed import\n // - doesn't use SSL/TLS\n\n {\n \"name\": \"cloudsql-source-instance\",\n \"region\": \"us-central1\",\n \"databaseVersion\": \"POSTGRES_9_6\",\n \"onPremisesConfiguration\": {\n \"selectedObjects\":[{\"database\":\"db1\"}, {\"database\":\"db3\"}],\n \"username\": \"newReplicationUser\",\n \"password\": \"525#@%*@\"\n }\n }\n\nThen, to modify the source representation instance in Cloud SQL, open\na Cloud Shell terminal and enter the following commands: \n\n### curl\n\n gcloud auth login\n ACCESS_TOKEN=\"$(gcloud auth print-access-token)\"\n curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header 'Content-Type: application/json' \\\n --data @\u003cvar translate=\"no\"\u003eJSON_PATH\u003c/var\u003e \\\n -X PATCH \\\n https://sqladmin.googleapis.com/sql/v1beta4/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/instances/\u003cvar translate=\"no\"\u003eSOURCE_NAME\u003c/var\u003e\n\n### example\n\n gcloud auth login\n ACCESS_TOKEN=\"$(gcloud auth print-access-token)\"\n curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header 'Content-Type: application/json' \\\n --data @./source.json \\\n -X PATCH \\\n https://sqladmin.googleapis.com/sql/v1beta4/projects/MyProject/instances/cloudsql-source-instance\n\nStart replication on the external server\n----------------------------------------\n\nAfter verifying that you can replicate from the external server, start the replication. The speed for performing the replication for the initial import process is up to 500 GB per hour. However, this speed can vary based on the machine tier, data disk size, network throughput, and nature of your database. \n\n### curl\n\n gcloud auth login\n ACCESS_TOKEN=\"$(gcloud auth print-access-token)\"\n curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header 'Content-Type: application/json' \\\n --data '{\n \"syncMode\": \"\u003cvar translate=\"no\"\u003eSYNC_MODE\u003c/var\u003e\",\n \"skipVerification\": \"\u003cvar translate=\"no\"\u003eSKIP_VERIFICATION\u003c/var\u003e\",\n \"syncParallelLevel\": \"\u003cvar translate=\"no\"\u003eSYNC_PARALLEL_LEVEL\u003c/var\u003e\"\n }' \\\n -X POST \\\n https://sqladmin.googleapis.com/sql/v1beta4/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/instances/\u003cvar translate=\"no\"\u003eREPLICA_INSTANCE_ID\u003c/var\u003e/startExternalSync\n\n### example\n\n gcloud auth login\n ACCESS_TOKEN=\"$(gcloud auth print-access-token)\"\n curl --header \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n --header 'Content-Type: application/json' \\\n --data '{\n \"syncMode\": \"online\",\n \"syncParallelLevel\": \"optimal\"\n }' \\\n -X POST \\\n https://sqladmin.googleapis.com/sql/v1beta4/projects/MyProject/instances/replica-instance/startExternalSync\n\nMonitor the migration\n---------------------\n\nOnce you start replication from the external server, you need to monitor\nreplication. To learn more, see\n[Monitoring replication](/sql/docs/postgres/replication/configure-replication-from-external#monitor_replication).\nYou can then complete your migration.\n\nTroubleshoot\n------------\n\nConsider the following troubleshooting options:\n\n### Review your replication logs\n\nWhen you [verify your replication settings](#verify-replication), logs are\nproduced.\n\nYou can view these logs by following these steps:\n\n1.\n Go to the Logs Viewer in the Google Cloud console.\n\n [Go to the Logs Viewer](https://console.cloud.google.com/logs?resource=cloudsql_database)\n2. Select the Cloud SQL replica from the **Instance** dropdown.\n3. Select the `replication-setup.log` log file.\n\nIf the Cloud SQL replica is unable to connect to the external server,\nconfirm the following:\n\n- Any firewall on the external server is configured to allow connections from the Cloud SQL replica's [outgoing IP address](#outgoing-ip).\n- Your SSL/TLS configuration is correct.\n- Your replication user, host, and password are correct.\n\nWhat's next\n-----------\n\n- Learn about [updating an instance](/sql/docs/postgres/edit-instance).\n- Learn about [managing replicas](/sql/docs/postgres/replication/manage-replicas).\n- Learn about [monitoring instances](/sql/docs/postgres/monitor-instance).\n- Learn about [promoting your Cloud SQL replica](/sql/docs/postgres/replication/manage-replicas#promote-replica)."]]