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"]],["上次更新時間:2025-05-15 (世界標準時間)。"],[[["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."]]],[]]