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 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."]]],[]]