遷移至 現有的目的地執行個體時,您會收到下列錯誤訊息: The destination instance contains existing data or user defined entities (for example databases, tables, or functions). You can only migrate to empty instances. Clear your destination instance and retry the migration job.
遷移至 現有的目的地執行個體時,您會收到下列錯誤訊息: The destination instance contains existing data or user defined entities (for example databases, tables, or functions). You can only migrate to empty instances. Clear your destination instance and retry the migration job.
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-18 (世界標準時間)。"],[[["\u003cp\u003eMigration jobs can encounter recoverable errors, which allow for automatic resumption after being fixed, or unrecoverable errors that necessitate a complete restart of the migration job.\u003c/p\u003e\n"],["\u003cp\u003eTroubleshooting errors involves navigating to the failed migration job to examine the error message and follow the provided steps, as well as consulting Cloud Monitoring logs for more details.\u003c/p\u003e\n"],["\u003cp\u003eCommon issues during migration include connectivity problems, incompatible database versions, data conflicts with existing destination instances, and issues with required settings and privileges.\u003c/p\u003e\n"],["\u003cp\u003eTo resolve issues where a destination instance has extra data, the migration job must be stopped, the destination instance promoted to read/write, extra data cleared, and then the migration job restarted.\u003c/p\u003e\n"],["\u003cp\u003eCertain errors, like those involving replication slots, require manual cleanup via specific commands executed by a user with superuser privileges, while others, like a deadlock issue in the \u003ccode\u003epglogical\u003c/code\u003e extension in PostgreSQL version 15, may require deleting the instance and starting a new migration job, or migrating to an intermediate PostgreSQL version.\u003c/p\u003e\n"]]],[],null,["# Diagnose issues for homogeneous migrations to Cloud SQL for PostgreSQL\n\n\u003cbr /\u003e\n\nThe migration job process might incur errors during runtime.\n\n- Some errors, such as a bad password on the source database, are recoverable, meaning they can be fixed and the migration job resumes automatically.\n- Some are unrecoverable, such as errors in data replication, meaning the migration job needs to be restarted from the beginning.\n\nWhen an error occurs, the migration job status changes to `Failed`, and the substatus reflects the last status before failure.\n\nTo troubleshoot an error, navigate to the failed migration job to view the error and follow the steps outlined in the error message.\n\nTo view more details about the error, navigate to Cloud Monitoring using the link on the migration job. The logs are filtered to the specific migration job.\n\nIn the following table, you can find some examples of issues and how they can be solved:\n\n### Clear extra data from your existing\ndestination instance\n\nWhen you migrate to [an existing destination instance](/database-migration/docs/postgres/create-migration-job-existing-instance), you receive the following error message:\n`The destination instance contains existing data or user defined\nentities (for example databases, tables, or functions). You can only\nmigrate to empty instances. Clear your destination instance and retry\nthe migration job.`\n\nThis issue can occur if your destination instance contains extra data.\nYou can only migrate to existing instances that are empty. See\n[Known limitations](/database-migration/docs/postgres/known-limitations#existing-instance-limitations).\n\n#### Things to try\n\nClear extra data from your destination instance and start the migration job\nagain by performing the following steps:\n\n1. [Stop the migration job](/database-migration/docs/postgres/migration-job-actions).\n2. At this point, your destination Cloud SQL instance is in \\`read-only\\` mode. [Promote the destination instance](/sql/docs/postgres/replication/configure-replication-from-external#promote_the_replica) to gain write access.\n3. [Connect to your destination Cloud SQL instance](/sql/docs/postgres/connect-overview).\n4. Remove extra data from your destination instance databases. Your destination can only contain system configuration data. Destination databases can't contain user data (such as tables). There are different SQL statements you can run on your databases to find non-system data, for example: \n\n #### Example SQL statement to retrieve non-system databases (click to expand)\n\n ```sql\n SELECT datname FROM pg_catalog.pg_database\n WHERE datname NOT IN ('cloudsqladmin', 'template1', 'template0', 'postgres');\n ``` \n\n #### Example SQL statement to retrieve non-system data in the `postgres` database (click to expand)\n\n The `postgres` database is a system database, but it can\n contain non-system data. Make sure you run these statements on the\n `postgres` database. If you use the `psql` client\n to connect to the destination instance, you can switch to another\n database without resetting your connection by using the\n [`\\connect {database_name_here}`](https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-META-COMMAND-C-LC) command. \n\n ```sql\n SELECT table_schema, table_name FROM information_schema.tables\n WHERE table_schema != 'information_schema' AND table_schema not like 'pg\\_%';\n\n SELECT routine_schema, routine_name FROM information_schema.routines\n WHERE routine_schema != 'information_schema' AND routine_schema not like 'pg\\_%';\n\n SELECT extname FROM pg_extension WHERE extname != 'plpgsql';\n \n ```\n5. [Start the migration job](/database-migration/docs/postgres/migration-job-actions).\n\n*** ** * ** ***\n\n\n### Clean up replication slots\n\nYou see one of the following messages:\n\n- `Cleanup may have failed on source due to error: generic::unknown: failed to connect to on-premises database.`\n- `Error promoting EM replica: finished drop replication with errors.`\n\n\u003cbr /\u003e\n\n#### The issue might be\n\nWhen promoting a Cloud SQL instance, if the source instance isn't reachable from the Cloud SQL instance (for example, the source instance isn't running, or you removed the Cloud SQL instance from the allow list of source instances), then the settings needed for the replication can't be cleaned up during the promotion of a migration job. You must clean up the replication slots manually.\n\n#### Things to try\n\nFor each database, run the following commands as a user with the `superuser` privilege:\n\n1. Get the replication slot names from the error message, and then run the following command to drop the slots, one by one:\n\n ```\n select pg_drop_replication_slot({slot_name});\n ```\n2. If the replication slot names aren't available in the error message, then run the following command to query for the existing replication slots:\n\n ```\n select pg_drop_replication_slot(slot_name) from pg_replication_slots where slot_name like '%cloudsql%' and active = 'f';\n ```\n3. If there are no Cloud SQL replicas using the source instance, then run the following command to clean up `pglogical` settings:\n\n select pglogical.drop_node(node_name) from pglogical.node where node_name like 'cloudsql';\n\n4. If the `pglogical` extension isn't needed anymore, then run the following command to uninstall the extension:\n\n ```\n DROP EXTENSION IF EXISTS pglogical;\n ```\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\n### Error message:\n`Cannot connect to invalid database`\n\nWhen migrating to PostgreSQL version 15, after multiple subsequent connection\nretry attempts one of the following symptoms occur:\n\n- You receive a `Cannot connect to invalid database` error message.\n- The [Storage usage\n migration job metric](/database-migration/docs/postgres/migration-job-metrics) shows no progress after a long time when the migration job is performing the full database dump.\n\n\u003cbr /\u003e\n\n#### The issue might be\n\nThis problem is often attributed to\nthe deadlock issue in the `pglogical` extension. For more\ninformation, see the\n[`pglogical` issue tracker in GitHub](https://github.com/2ndQuadrant/pglogical/issues/418).\n\n#### Things to try\n\n##### Perform the migration job again with a new destination instance\n\nTry deleting the destination database where you experienced the issue\nand re-create your migration job. Follow these steps:\n\n1. Delete the destination instance where you experienced the problems. See [Delete instances](/sql/docs/postgres/delete-instance) in Cloud SQL for PostgreSQL documentation.\n2. Delete the failed migration job. See [Review a migration job](/database-migration/docs/postgres/review-migration-job).\n3. Re-create your migration job. See [Create a migration job](/database-migration/docs/postgres/create-migration-job).\n\n\u003cbr /\u003e\n\n##### Migrate to an intermediate version\n\nConsider migrating to an earlier PostgreSQL version, such as PostgreSQL 14.\nAfter a successful migration, you can try upgrade to the desired PostgreSQL 15\ninstance. See\n[Upgrade the database major version by migrating data](/sql/docs/postgres/upgrade-major-db-version-migrate) in Cloud SQL for PostgreSQL documentation.\n\n\n### Manage users and roles\n\n\u003cbr /\u003e\n\n#### Migrate existing users\n\nCurrently, Database Migration Service doesn't support migrating existing users from a source instance into a destination Cloud SQL instance. You can manage this migration by [creating the users in Cloud SQL](/sql/docs/postgres/create-manage-users) manually.\n\n#### About the `cloudsqlexternalsync` user\n\nDuring the migration, all objects on the Cloud SQL replica are owned by the `cloudsqlexternalsync` user. After the data is migrated, you can modify the ownership of the objects to other users by completing the following steps:\n\n- Run the `GRANT cloudsqlexternalsync to `\u003cvar translate=\"no\"\u003e{USER}\u003c/var\u003e command.\n- On each database, run the `reassign owned by cloudsqlexternalsync to `\u003cvar translate=\"no\"\u003e{USER}\u003c/var\u003e`;` command.\n- To remove the `cloudsqlexternalsync` user, run the `drop role cloudsqlexternalsync` command.\n\n#### Import data into a new Cloud SQL instance\n\nIf you first [export data](/sql/docs/postgres/import-export/import-export-sql) from a Cloud SQL instance that Database Migration Service migrated into Cloud Storage, and then [import the data](/sql/docs/postgres/import-export/import-export-sql) from Cloud Storage into a stand-alone Cloud SQL instance, the import might fail because the `cloudsqlexternalsync` user doesn't exist on the destination instance.\n\nTo mitigate the issue, either [create the `cloudsqlexternalsync` user](/sql/docs/postgres/create-manage-users) on the destination instance or [remove the user](#about-the-cloudsqlexternalsync-user) from the migrated instance."]]