Resolve a logical replication conflict (disable_on_error, SKIP)
PostgreSQLLogical ReplicationCommand
-- 1) Prevent a failing apply worker from looping forever:
ALTER SUBSCRIPTION sub_app SET (disable_on_error = true);
-- 2) Find the finish LSN of the conflicting transaction in the subscriber log:
-- CONTEXT: ... in transaction 749, finished at 0/5035378
-- 3a) Preferred: fix/delete the conflicting row on the subscriber, then re-enable:
ALTER SUBSCRIPTION sub_app ENABLE;
-- 3b) Or skip the whole remote transaction (NONE of its changes are applied on the subscriber):
ALTER SUBSCRIPTION sub_app SKIP (lsn = '0/5035378');
ALTER SUBSCRIPTION sub_app ENABLE;
SELECT subname, subenabled, subskiplsn FROM pg_subscription;What it does
When an error such as a duplicate key, missing row or permission problem stops apply on the subscriber: disable_on_error disables the subscription automatically; either fix the conflicting data and ENABLE, or SKIP the entire remote transaction identified by the 'finished at' LSN in the log.
When to use it
When the apply worker fails and keeps restarting because of direct writes on the subscriber, an incomplete initial copy or bidirectional writes.
Caution
SKIP also discards the non-conflicting changes in that transaction and the two sides diverge permanently; prefer fixing the data, and compare the table after a SKIP. Until the conflict is resolved, the slot on the publisher keeps accumulating WAL. Prevent application writes to subscriber tables with privileges.