liveBook · Manning

Sequence synchronization

As explained in PostgreSQL Mistakes and How to Avoid Them

Sequence synchronization is the coordination of generated numeric values across database nodes so that replicated writes do not reuse identifiers.

Sequence synchronization coordinates generated identifiers across database nodes so replicated writes do not reuse primary-key values. In bidirectional logical replication, each node must avoid generating numbers already used elsewhere. section 5.5

The duplicate-key failure

After alpha inserts rows with IDs 1 and 2, beta’s sequence may still be at 1. Inserting a row on beta then fails with duplicate key value violates unique constraint "tickets_pkey" because ID 1 already exists.

Common coordination strategies expose different operational costs:

  • Keep the entire cluster synchronized after every write, preserving coordination at the cost of disastrous performance. section 5.5
  • Pre-allocate distinct identifier ranges to nodes, accepting administrative work for allocation, exhaustion, and new-node management. section 5.5

How PostgreSQL Mistakes and How to Avoid Them covers it

How deep it goes
Explains the duplicate-key failure and two coordination strategies, but stops short of prescribing a complete allocation design.
Examples
Demonstrates alpha and beta generating conflicting ticket identifiers and producing a duplicate-key error.
What it assumes
Assumes familiarity with primary keys, sequences, and logical replication.
What you can do after
Operate multi-node writes by choosing between cluster-wide synchronization and pre-allocated identifier ranges.
How it connects
Connects sequences with primary keys, unique constraints, logical replication, and multi-master replication.

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.