首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由于重复密钥冲突导致PostgreSQL数据库复制失败

由于重复密钥冲突导致PostgreSQL数据库复制失败
EN

Stack Overflow用户
提问于 2020-02-14 11:32:18
回答 1查看 646关注 0票数 0

我已经配置了两台具有冗余配置的RHEL机器(主主安装程序)和下面的软件版本。

  • 数据库: PostgreSQL 9.5
  • Bucardo : Bucardo 5.4

数据库复制一直顺利进行,直到某个时候,在复制突然停止之后。我可以在布卡多日志中看到下面的一些陈述。

代码语言:javascript
复制
*KID (database_sync) Conflicts for public.interface: 4
KID (database_sync) Conflicts have been resolved
KID (database_sync) Warning! Aborting due to exception for public.interface:? Error was DBD::Pg::db pg_putcopyend failed: ERROR:  duplicate key value violates unique constraint "interface_nodeid_ifindex_unique_idx"\nDETAIL:  Key (nodeid, ifindex)=(81, 1) already exists.\nCONTEXT:  COPY interface, line 2 at /usr/share/perl5/vendor_perl/Bucardo.pm line 9879.
KID (database_sync) Kid has died, error is: DBD::Pg::db pg_putcopyend failed: ERROR:  duplicate key value violates unique constraint "interface_nodeid_ifindex_unique_idx"\nDETAIL:  Key (nodeid, ifindex)=(81, 1) already exists.\nCONTEXT:  COPY interface, line 2 at /usr/share/perl5/vendor_perl/Bucardo.pm line 9879. Line: 5041 Main DB state: ? Error: none DB database_node1 state: ? Error: none DB database_node2 state: 23505 Error: 7
DBI::db=HASH(0x2e1a708)->disconnect invalidates 9 active statement handles (either destroy statement handles or call finish on them before disconnecting) at /usr/share/perl5/vendor_perl/Bucardo.pm line 2756.
DBI::db=HASH(0x2e1a828)->disconnect invalidates 9 active statement handles (either destroy statement handles or call finish on them before disconnecting) at /usr/share/perl5/vendor_perl/Bucardo.pm line 2756.
KID (database_sync) Kid 22825 exiting at cleanup_kid. Sync "database_sync" public.interface Reason: DBD::Pg::db pg_putcopyend failed: ERROR:  duplicate key value violates unique constraint "interface_nodeid_ifindex_unique_idx"\nDETAIL:  Key (nodeid, ifindex)=(81, 1) already exists.\nCONTEXT:  COPY interface, line 2 at /usr/share/perl5/vendor_perl/Bucardo.pm line 9879. Line: 5041 Main DB state:

?错误:无DB database_node1状态:?错误:无数据库database_node2状态: 23505错误:7 MCP启动check_sync_health*

下面是我创建同步的步骤。

代码语言:javascript
复制
bucardo add database bucardo add table all --db="$database"_node1    --herd="$database"_herd 
bucardo add sequence all --db="$database"_node1 --herd="$database"_herd 
bucardo add dbgoup "$database"_group 
bucardo add dbgroup "$database"_group    "$database"_node1:source 
bucardo add dbgroup "$database"_group    "$database"_node2:source 
bucardo add sync "$database"_sync    herd="$database_herd"_herd dbs="$database"_group    conflict_strategy=bucardo_latest onetimecopy=2 stayalive=1    kidsalive=1 autokick=1 systemctl enable bucardo.service

请你帮我把你对这个问题的调查结果告诉我。我的数据库中的序列可以负责创建数据库中的重复条目吗?

EN

回答 1

Stack Overflow用户

发布于 2020-07-04 18:03:15

当用户使用序列进行多源设置时,不能复制,否则就会出现冲突,因为您已经进行了实验。

  • 从同步中删除序列。我是从内存中写的,而不是测试它,所以小心

代码语言:javascript
复制
bucardo remove sequence all
bucardo validate all
bucardo reload

  • 更改每个源中的序列,以避免在两个数据库中创建相同的主键。Check this answer用于几个选项,如生成偶数、奇数;生成db1中的1、11、21、db2中的2、12、22等数字;或使用UUID.

.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60225499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档