From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Record logical replication conflicts in the conflict log table.
Date: Tue, 24 Nov 2026 11:41:51 +0000
Message-ID: <E1xVouF-000000008Q7-0PyQ@gemulon.postgresql.org> (raw)
Record logical replication conflicts in the conflict log table.
Populate the conflict log table whenever a logical replication conflict is
detected. Each row records the remote transaction (xid, final LSN, commit
timestamp), the replica identity key of the conflicting row, and metadata
of the local conflicting tuples.
Only resolved (LOG-level) conflicts are recorded in the table. Conflicts
that raise an ERROR (such as unique constraint violations) halt
replication and abort the transaction, so they are logged exclusively to
the server log. Conflict log tables are also excluded from logical
decoding.
To avoid serializing full tuples that could exceed the 1GB varlena limit
and halt the apply worker, the 'remote_tuple' column is removed from the
table and 'local_conflicts' records only transaction metadata. Tables
using REPLICA IDENTITY FULL set 'replica_identity_full' to true with
'replica_identity' set to NULL. For other tables, 'replica_identity' can
be used to identify the conflicting tuple.
replica_identity: When the table has a replica identity index or primary
key, this column stores a JSON object keyed by column name. A value whose
output exceeds 64kB is replaced by a marker recording its length
({"omitted":true,"length":...}), and 'has_omitted_values' is set to true.
Values are omitted rather than truncated so that join predicates against
the table never silently give wrong answers.
local_conflicts: This column is an array of JSON objects (json[]), so that
conflicts involving several local tuples can be recorded in the future.
Each element has the format:
[ { "xid": "1001", "commit_ts": "2025-12-25 10:00:00+05:30", "origin": "node_1" }, ... ]
Example:
SELECT remote_xid, relname, apply_origin, replica_identity,
local_conflicts[1] ->> 'xid' AS local_xid
FROM pg_conflict.pg_conflict_log_16396;
remote_xid | relname | apply_origin | replica_identity | local_xid
------------+----------+---------------+------------------+-----------
760 | test | pg_16406 | {"a":"1"} | 771
765 | conf_tab | pg_16406 | {"a":"2"} | 775
With two_phase enabled, a prepared transaction that recorded a conflict
holds a lock on the conflict log table until the apply worker finishes it.
Dropping the table would wait for that lock, while DROP SUBSCRIPTION and
ALTER SUBSCRIPTION ... SET (conflict_log_destination = 'log') also keep the
worker from finishing it, so they could hang. Refuse both while prepared
transactions exist.
Preserving the conflict log table across pg_upgrade is handled in a
separate follow-up patch.
Bumped catversion as the schema of conflict history table is changed.
Based on design inputs by Amit Kapila and Sawada Masahiko.
Author: Dilip Kumar <dilipbalaut@gmail.com>
Author: Nisha Moond <nisha.moond412@gmail.com>
Author: Zhijie Hou <houzhijie22@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Reviewed-by: Kedar Anavardekar <kedar.anavardekar@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Narayanan Venkateswaran <narayananvpostgres@gmail.com>
Discussion: https://postgr.es/m/CAFiTN-u5D5o_AGNbHRZHaOqAMWkxLf+hSk_r9X3gv6HbLOB5+g@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/6a0a66b3e7ac394c499708b790effea9a564ef0d
Modified Files
--------------
doc/src/sgml/logical-replication.sgml | 824 +++++++++++++++++++----------
doc/src/sgml/ref/alter_subscription.sgml | 12 +-
doc/src/sgml/ref/create_subscription.sgml | 31 +-
doc/src/sgml/ref/drop_subscription.sgml | 16 +-
src/backend/commands/subscriptioncmds.c | 125 ++++-
src/backend/executor/execReplication.c | 36 +-
src/backend/replication/logical/conflict.c | 659 +++++++++++++++++++++--
src/backend/replication/logical/worker.c | 146 +++--
src/include/catalog/catversion.h | 2 +-
src/include/executor/executor.h | 6 +-
src/include/replication/conflict.h | 9 +-
src/include/replication/worker_internal.h | 5 +
src/include/utils/rel.h | 13 +-
src/test/regress/expected/subscription.out | 13 +-
src/test/regress/sql/subscription.sql | 7 +
src/test/subscription/t/035_conflicts.pl | 342 +++++++++++-
16 files changed, 1854 insertions(+), 392 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: akapila@postgresql.org
Subject: Re: pgsql: Record logical replication conflicts in the conflict log table.
In-Reply-To: <E1xVouF-000000008Q7-0PyQ@gemulon.postgresql.org>
References: <E1xVouF-000000008Q7-0PyQ@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox