liveBook · Manning

Write conflict

As explained in PostgreSQL Mistakes and How to Avoid Them

A data conflict is an incompatible set of replicated changes that cannot be applied together without violating a data constraint or intended state.

A write conflict occurs when replicated changes cannot coexist with a primary-key, unique, or schema constraint. In bidirectional PostgreSQL logical replication, independently generated sequence values make this failure easy to trigger. section 5.5

Duplicate identity across nodes

After both nodes contain tickets with IDs 1–3, beta inserts another ticket while its sequence is still at 1. PostgreSQL rejects the replicated row with a duplicate-key error because alpha already used ID 1. Avoid reuse by synchronizing writes across the cluster or pre-allocating non-overlapping ranges, accepting the performance or administrative cost. section 5.5

Schema drift as a replication conflict

Renaming opened_at to logged_at on beta while alpha continues inserting leaves the target without the replicated column. The replication worker enters a crash/restart loop, so schema changes require coordinated orchestration. section 5.5

How PostgreSQL Mistakes and How to Avoid Them covers it

How deep it goes
Explains primary-key collisions, sequence coordination, schema drift, and replication-worker failure, but not conflict-resolution algorithms.
Examples
Uses replicated ticket inserts, a duplicate key error, a column rename, and a missing-column replication log.
What it assumes
Assumes familiarity with PostgreSQL tables, primary keys, sequences, logical replication, and schema changes.
What you can do after
Diagnose conflicts with SQL results and PostgreSQL logs, then coordinate sequences and schema changes before enabling writes.
How it connects
Connects logical replication with primary keys, unique constraints, sequences, schema changes, and multi-master deployment.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of PostgreSQL Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.