Disabled logical replication origin session causes primary key errors

From: Shawn McCoy <shawn(dot)the(dot)mccoy(at)gmail(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: swada(dot)mshk(at)gmail(dot)com, drewwcallahan(at)gmail(dot)com, "scott(at)meads(dot)us" <scott(at)meads(dot)us>
Subject: Disabled logical replication origin session causes primary key errors
Date: 2025-04-18 21:22:00
Message-ID: CALsgZNCGARa2mcYNVTSj9uoPcJo-tPuWUGECReKpNgTpo31_Pw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello,

We have discovered a recent regression in the Origin handling of logical
replication apply workers. We have found the cause of the issue was due to
the worker resetting its local origin session information during the
processing of an error that is
silently handled allowing the worker to continue. We suspect this is caused
by the recent change made in the following thread,
https://www.postgresql.org/message-id/TYAPR01MB5692FAC23BE40C69DA8ED4AFF5B92@TYAPR01MB5692.jpnprd01.prod.outlook.com
.

The logical replication apply worker will originally setup the origin
correctly. However, on the first insert will call into the trigger which
will raise an exception. This exception will execute the error callback
that resets the origin session state. The exception will then be silently
handled, returning execution back to the apply worker. In the second
reproduction, a function based index is used with the same result.

At this point, the apply worker can continue to commit these changes, but
has cleared all local origin session state. As a result, we will not update
our remote to local LSN mapping of the origin. Allowing for duplicate data
to be applied.

This was tested and observed in at least these versions:

PostgreSQL 16.8
PostgreSQL 17.4

We provide a simple reproduction of the issue below in 2 separate use-cases.

Regards,
Shawn McCoy, Drew Callahan, Scott Mead

Attachment Content-Type Size
repro_local_origin_stuck.txt text/plain 1.3 KB
repro_local_origin_stuck_causing_duplicate_key.txt text/plain 3.4 KB

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-04-19 19:33:20 Re: BUG #18896: A potential problem in heap_page_items (pageinspect, PG-17)
Previous Message Tom Lane 2025-04-18 17:38:50 Re: BUG #18899: FreeBSD, assembly by means of GCC with ASAN ends with error: undef reference to backtrace_symbols_fd