对于没有主键的表,Database Migration Service 支持在变更数据捕获 (CDC) 阶段迁移初始快照和 INSERT 语句。
如需更新缺少的 UPDATE 和 DELETE 进程,请参阅本文档的后续部分。
检测源代码和 AlloyDB 目标集群之间缺失的数据
确定哪些表没有主键:
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-04-17。"],[[["This page provides debugging scripts and guidance for using AlloyDB, particularly focusing on data migration from PostgreSQL."],["Database Migration Service supports the initial snapshot and `INSERT` statements for tables without primary keys during migration, but manual steps are needed for `UPDATE` and `DELETE` operations."],["You can detect potential data discrepancies between the source and destination by identifying tables without primary keys and tracking `INSERT`, `UPDATE`, and `DELETE` activity using queries against `information_schema` and `pg_stat_user_tables`."],["If discrepancies are detected, manual migration options include comparing data and running SQL queries, utilizing `pg_dump` and `pg_restore`, or employing the Postgres `COPY` command, which might require pre-migration data cleanup on the replica."]]],[]]