Re: Logical replication can lose an update after concurrent index invalidation

From: vignesh C <vignesh21(at)gmail(dot)com>
To: Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, onderkalaci(at)gmail(dot)com
Subject: Re: Logical replication can lose an update after concurrent index invalidation
Date: 2026-08-28 06:50:03
Message-ID: CALDaNm3qy+J01N2qfxSTO6_XaW_9ZUwHX73FwZnzr0Rvpv6nDA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 28 Aug 2026 at 03:05, Mihail Nikalayeu
<mihailnikalayeu(at)gmail(dot)com> wrote:
>
> Attached are patches for master (which also applies to v19 as-is),
> v18, v17 and v16. The back-branch patches contain the code change
> only. The test requires the injection point added by bc32a12e0db; v18
> and v17 don't have it, and it can't be used on v16.

RelationFindReplTupleByIndex() is an extern function declared in a
core executor header (executor.h). Adding a new parameter
(isIdxSafeToSkipDuplicates) changes its calling convention. Any
third-party extension or out-of-tree apply worker compiled against an
earlier minor version like PG16 branch that calls this function will
pass incorrect arguments on the stack/registers, leading to stack
corruption or crashes when running on a patched minor release.
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -652,6 +652,7 @@ extern void check_exclusion_constraint(Relation
heap, Relation index,
* prototypes from functions in execReplication.c
*/
extern bool RelationFindReplTupleByIndex(Relation rel, Oid idxoid,
+ bool isIdxSafeToSkipDuplicates,
LockTupleMode lockmode,
TupleTableSlot *searchslot,
TupleTableSlot *outslot);

Similarly I'm not sure of adding isidentity to LogicalRepRelMapEntry
in back branches as it will change its size and memory layout.
External extensions that embed, allocate, or iterate over arrays of
LogicalRepRelMapEntry across minor releases will experience struct
size mismatches and potential memory misalignment.
diff --git a/src/include/replication/logicalrelation.h
b/src/include/replication/logicalrelation.h
index 3f4d906d741..4f98b1ea789 100644
--- a/src/include/replication/logicalrelation.h
+++ b/src/include/replication/logicalrelation.h
@@ -33,6 +33,11 @@ typedef struct LogicalRepRelMapEntry
AttrMap *attrmap; /* map of local attributes to remote ones */
bool updatable; /* Can apply updates/deletes? */
Oid localindexoid; /* which index to use, or InvalidOid if none */
+ bool isidentity; /* localindexoid was chosen as the
+ * relation's replica identity or
+ * primary key, rather than as one
+ * usable for a REPLICA IDENTITY
+ * FULL remote relation */

Regards,
Vignesh

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2026-08-28 06:53:38 Re: Offline data checksum changes can cause incorrect checksum state on standbys
Previous Message Tender Wang 2026-08-28 06:39:18 Re: [PATCH] Fix disabled_nodes propagation for single-child Append paths