Proposal: Conflict log history table for Logical Replication - #407
pg-hub-mirror[bot] wants to merge 2 commits into
Conversation
…table
This patch introduces the core logic to populate the conflict log table whenever
a logical replication conflict is detected. It captures the remote transaction
details along with the corresponding local state at the time of the conflict.
Only resolved (LOG-level) conflicts are recorded in the conflict log 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.
Local Conflicts Column: The 'local_conflicts' column is typed as an array of
JSON objects (json[]). Although currently recorded conflicts involve a single
local tuple, the column type is preserved as a JSON array for future-proofing.
This avoids modifying the exposed table schema and dealing with upgrade handling
when multi-row conflict resolution is introduced in the future.
The JSON array uses the following structured format:
[ { "xid": "1001", "commit_ts": "2025-12-25 10:00:00+05:30", "origin": "node_1",
"tuple": {"id": 1, "val": "old_data"} }, ... ]
Example of querying the structured conflict data:
SELECT remote_xid, relname, remote_origin, local_conflicts[1] ->> 'xid' AS local_xid,
local_conflicts[1] ->> 'tuple' AS local_tuple
FROM pg_conflict.pg_conflict_log_16396;
remote_xid | relname | remote_origin | local_xid | local_tuple
------------+----------+---------------+-----------+---------------------
760 | test | pg_16406 | 771 | {"a":1,"b":10}
765 | conf_tab | pg_16406 | 775 | {"a":2,"b":2,"c":2}
The remote transaction details (xid, final LSN, commit timestamp) recorded
in the conflict log table are fetched from the apply worker's remote
transaction context through GetRemoteTransactionInfoForConflict() instead of
new global variables.
|
Earlier design discussion: Discussion #179 |
|
shveta malik <shveta(dot)malik(at)gmail(dot)com> via pgsql-hackers · original email v74 needs a rebase; it isn't compiling due to commit 926627b which |
|
shveta malik <shveta(dot)malik(at)gmail(dot)com> via pgsql-hackers · original email On Fri, Sep 18, 2026 at 1:35 PM Nisha Moond <nisha(dot)moond412(at)gmail(dot)com> wrote:
I agree. I too noticed this. Need to think more here. |
pgsql-hackersCAFiTN-uZfzOC9Fo6ga4RhR0RohEVWWmegHEP3n=F0uKiJTzWqA@mail.gmail.comPatch files:
On Wed, Sep 16, 2026 at 8:56 AM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
Thanks Sawada-san for you detailed analysis.