【问题标题】:disable duplicate key constraint for postgres migration禁用 postgres 迁移的重复键约束
【发布时间】:2021-04-08 05:14:42
【问题描述】:

我正在尝试将一些数据从一个 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.

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

【问题讨论】:

    标签: postgresql amazon-rds


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您是否检查过任何引用键?您可能想查询 id 和 March 以查看是否有任何 id 引用了自身,如果是,则将其视为重复并引发错误

      【讨论】:

      • 对不起...错过了错误的一个关键部分...刚刚编辑它...它是引发 dup 密钥错误的 ssnhash:DETAIL: Key (ssnhash)=(3895fa77f6d70c8c9401275829c78020) already exists.
      猜你喜欢
      • 1970-01-01
      • 2020-08-14
      • 2013-09-10
      • 2022-08-22
      • 2021-08-14
      • 2018-12-07
      • 2018-04-05
      • 1970-01-01
      • 2018-04-01
      相关资源
      最近更新 更多