简体   繁体   中英

Primary-key collisions in multi-master replication environment using django

I have a multi-master replication setup using Postgres and Bucardo. On top of it, I have a Django application.

The setup does not fully works since I keep getting primary-key collisions. Since the replication is configured to clone the whole database, and thus I'm somewhat confident that Postgres' sequence ids are being updated, I wonder if it is not Django that keeps somewhere in memory the last sequential id number. If so, does anyone have any hint on what could be done to fix this issue?

Thanks in advance

Attempting multi-master replication without an idea how to deal with conflicts is foolhardy.

This case is simple: define the sequences on each node so that the values cannot collide. If you have two databases, that would be:

CREATE SEQUENCE tab_id_seq START WITH 1 INCREMENT BY 2;  -- on one database
CREATE SEQUENCE tab_id_seq START WITH 2 INCREMENT BY 2;  -- on the other database

But you will hit other replication conflicts that are harder to resolve.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM