对于没有主键的表,Database Migration Service 支持在变更数据捕获 (CDC) 阶段迁移初始快照和 INSERT 语句。
如需更新缺少的 UPDATE 和 DELETE 进程,请参阅本文档的后续部分。
检测源实例和 Cloud SQL 目标实例之间缺失的数据
确定哪些表没有主键:
select tab.table_schema,
tab.table_name
from information_schema.tables tab
left join information_schema.table_constraints tco
on tab.table_schema = tco.table_schema
and tab.table_name = tco.table_name
and tco.constraint_type = 'PRIMARY KEY'
where tab.table_type = 'BASE TABLE'
and tab.table_schema not in ('pg_catalog', 'information_schema', 'pglogical')
and tco.constraint_name is null
order by table_schema,
table_name;
在开始迁移之前,请针对没有主键的所有表,使用以下查询检查是否有任何更新或删除操作:
SELECT schemaname,
relname,
n_tup_ins,
n_tup_upd,
n_tup_del
FROM pg_stat_user_tables
WHERE schemaname NOT IN
('pglogical', 'pg_catalog', 'information_schema');
[[["易于理解","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-03-27。"],[[["This page provides debugging scripts and guidance for using PostgreSQL within the Database Migration Service."],["Database Migration Service supports the migration of initial snapshots and `INSERT` statements for tables without primary keys, but `UPDATE` and `DELETE` operations may need manual intervention."],["You can identify tables lacking primary keys and check for any updates or deletes on the source during migration using the provided SQL queries against the `information_schema` and `pg_stat_user_tables` tables."],["If data discrepancies are found between the source and the Cloud SQL destination instance, you can manually resolve them by comparing and updating data, or by utilizing `pg_dump`/`pg_restore` or the `COPY` command for the affected tables."],["It is important to potentially clean the replica before using `pg_restore` or `COPY` commands if there is data that was previously migrated."]]],[]]