Skip to content

Conflict resolution and standby failover

Choose deterministic conflict rules for bidirectional Spock replication, monitor apply workers, and rehearse standby promotion.

Choose conflict arbitration rules

Asynchronous multi-master replication allows two nodes to commit writes to the same row before replicating to each other. Before adding a table to a spock replication set, configure track_commit_timestamp = on on every node and match each table column pattern to a deterministic conflict rule:

  • Last-update-wins (last_update_wins): Resolves concurrent INSERT/UPDATE conflicts using commit timestamps; Mimus kernel layers 200 / 201 preserve surviving subtransaction commit timestamps inside COMMIT WAL so physical standbys see identical timestamps.
  • Delta-apply (spock.delta_apply): For numeric counters and balances, enable log_old_value = true and delta_apply_function = spock.delta_apply on the column so concurrent increments and decrements commute cleanly.
  • Distributed IDs: Avoid colliding SERIAL sequences across writable nodes by assigning disjoint sequence ranges, UUIDs, or the pgEdge Snowflake extension.

Monitor subscriptions and conflict logs

Check subscription state, replication slot lag, and recorded conflict history on every writable node:

SELECT subscription_name, status FROM spock.sub_show_status();
SELECT slot_name, active, confirmed_flush_lsn,
       pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained
  FROM pg_replication_slots WHERE plugin = 'spock_output';
SELECT relname, conflict_type, conflict_resolution, local_timestamp, remote_timestamp
  FROM spock.resolutions ORDER BY id DESC LIMIT 10;

See pgEdge conflict operations for detailed diagnostics.

Rehearse physical standby promotion

When pairing Spock logical nodes with local physical HA standbys:

  • Ensure every physical standby runs a Mimus kernel built through layer 201 (or full 401) so it can replay Spock’s custom COMMIT WAL records generated during subtransaction conflict resolution; stock community PostgreSQL binaries cannot replay those records.
  • Synchronize logical replication slot positions (sync_replication_slots or controlled slot failover) and encryption key providers on standbys before rehearsing promotion; see pgEdge recovery boundaries.
Scan to open this page
https://mimus.pgsty.com/docs/guides/failover-and-conflicts/