首页 > 解决方案 > 禁用 postgres 迁移的重复键约束

问题描述

我正在尝试将一些数据从一个 postgres rds 迁移到另一个 postgres rds,但我一直遇到ERROR: duplicate key value violates unique constraint "abcd_xyz". 我已将session_replication_role参数组值更新为replica但似乎仍然无法超越该约束(以及我会遇到的其他约束)。

演示数据,但即使我设置set session_replication_role to 'replica';...我仍然得到同样的错误

user ~/Git/go-dlp  $ psql -h blah.us-east-1.rds.amazonaws.com -U user1 -d db1 
Password for user user1: 
psql (13.2, server 11.6)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

db1=> 
db1=> 
db1=> set session_replication_role to 'replica';
SET
db1=> UPDATE userinfo_v3 SET firstname = 'Alana', lastname = 'Crooks', mobilephone = '+17368645273', ssn = '666612345', ssnhash = '3895fa77f6d70c8c9401275829c78020' WHERE id = '73838726';
UPDATE 1
db1=> UPDATE userinfo_v3 SET firstname = 'Leann', lastname = 'Crist', mobilephone = '+16970011319', ssn = '666612345', ssnhash = '3895fa77f6d70c8c9401275829c78020' WHERE id = '1470593';
ERROR:  duplicate key value violates unique constraint "abcd_xyz"
DETAIL:  Key (ssnhash)=(3895fa77f6d70c8c9401275829c78020) already exists.

我想我已经设置了所有正确的参数,但由于某种原因我仍然无法超越那个限制

标签: postgresqlamazon-rds

解决方案


您不能禁用主键或唯一约束。session_replication_role仅影响触发器和外键约束。

您唯一的选择是删除约束并在完成后重新创建它。


推荐阅读