postgresql - 禁用 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.
我想我已经设置了所有正确的参数,但由于某种原因我仍然无法超越那个限制
解决方案
您不能禁用主键或唯一约束。session_replication_role
仅影响触发器和外键约束。
您唯一的选择是删除约束并在完成后重新创建它。
推荐阅读
- javascript - 在不提交页面的情况下单击按钮显示文件
- list - 如何在groovy中恢复hashmap key&value中的结果
- java - Marshaller 必须支持带有 spring 批处理的 split job 中的 marshalled object 错误的类
- error-handling - 为什么 TCL CATCH 命令不返回错误?
- python - 计算列表的平均值
- php - 我们如何通过来自其他页面的点击事件来停止像 shell_exec() 或 exec() 这样的进程?
- java - 升级 commons-lang-2.6.jar 会抛出 NoClassDefFoundError
- php - 我会尝试通过php中的网页读取串口数据来读取重量机器数据
- c# - 在 C# 中从后端发送 UWP 原始通知
- javascript - 如何确保 billboard.js 系列在 onrendered 中结束了所有转换?