Re: Proposal: Conflict log history table for Logical Replication
Dilip Kumar <dilipbalaut@gmail.com>
From: Dilip Kumar <dilipbalaut@gmail.com>
To: shveta malik <shveta.malik@gmail.com>
Cc: Peter Smith <smithpb2250@gmail.com>,
Amit Kapila <amit.kapila16@gmail.com>, Masahiko Sawada <sawada.mshk@gmail.com>, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-11-26T11:18:50Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Allow logical replication conflicts to be logged to a table.
- a5918fddf10d master landed
-
Avoid orphaned objects dependencies
- 2fbb21170e90 19 (unreleased) cited
Attachments
- v7-0001-Add-configurable-conflict-log-table-for-Logical-R.patch (application/octet-stream) patch v7-0001
On Wed, Nov 26, 2025 at 4:15 PM shveta malik <shveta.malik@gmail.com> wrote: > > On Wed, Nov 26, 2025 at 2:05 PM shveta malik <shveta.malik@gmail.com> wrote: > > > > On Tue, Nov 25, 2025 at 4:06 PM Dilip Kumar <dilipbalaut@gmail.com> wrote: > > > > > > On Tue, Nov 25, 2025 at 1:59 PM Dilip Kumar <dilipbalaut@gmail.com> wrote: > > > > > > > > > > On a separate note, I've been considering how to manage conflict log > > > insertions when an error causes the outer transaction to abort, which > > > seems to be a non-trivial. > > > > > > Here is what I have in mind: > > > ====================== > > > First, prepare_conflict_log() would be executed from > > > ReportApplyConflict(). This function would handle all preliminary > > > work, such as preparing the tuple for the conflict log table. Second, > > > insert_conflict_log() would be executed. If the error level in > > > ReportApplyConflict() is LOG, the insertion would occur directly. > > > Otherwise, the log information would be stored in a global variable > > > and inserted in a separate transaction once we exit start_apply() due > > > to the error. > > > > > > @shveta malik @Amit Kapila let me know what you think? Or do you > > > think it can be simplified? > > > > > > > I could not think of a better way. This idea works for me. I had > > doubts if it will be okay to start a new transaction in catch-block > > (if we plan to do it in start_apply's), but then I found few other > > functions doing it (see do_autovacuum, perform_work_item, > > _SPI_commit). So IMO, we should be good. > > > > On re-reading, I think you were not suggesting to handle it in the > CATCH block. Where exactly once we exit start_apply? > But since the situation will arise only in case of ERROR, I thought > handling in catch-block could be one option. Yeah it makes sense to handle in catch block, I have done that in the attached patch and also handled other comments by Peter. Now pending work status 1) fixed review comments of 0002 and 0003 - Pending 2) Need to add replica identity tuple instead of full tuple -- Done 3) Keeping the logs in case of outer transaction failure by moving log insertion outside the main transaction - reported by Shveta - Done (might need more validation and testing) 4) Run pgindent -- planning to do it after we complete the first level of review - Pending 5) Subscription test cases for logging the actual conflicts - Pending -- Regards, Dilip Kumar Google