Skip to content

Logical replication can lose an update after concurrent index invalidation - #436

Open
pg-hub-mirror[bot] wants to merge 1 commit into
masterfrom
pg-hub/mirror-patch-6ee63ff5d58a64d2
Open

pg-hub-mirror[bot] wants to merge 1 commit into
masterfrom
pg-hub/mirror-patch-6ee63ff5d58a64d2

Conversation

@pg-hub-mirror

@pg-hub-mirror pg-hub-mirror Bot commented Sep 18, 2026

Copy link
Copy Markdown

Read-only mirror. Reply and review on pgsql-hackers; activity here is not sent upstream.

  • Original author: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
  • Mailing list: pgsql-hackers
  • Message-ID: CAA4eK1Jvw2h7ycGDTr6YXL22BUC-TC+dbM7z3Gs+B8MnHJqDug@mail.gmail.com
  • Original email

Patch files:


On Mon, Sep 7, 2026 at 9:04 PM vignesh C <vignesh21(at)gmail(dot)com> wrote:

On Thu, 3 Sept 2026 at 16:15, Mihail Nikalayeu
<mihailnikalayeu(at)gmail(dot)com> wrote:

Zhijie, Amit, thanks for the reviews!

we shall mention in the comments atop the old function that it should
not be used in new code anymore

Done.

Couple of minor comments:

  1. I was able to compile without this header inclusion:
    --- a/src/backend/replication/logical/worker.c
    +++ b/src/backend/replication/logical/worker.c
    @@ -249,6 +249,7 @@

#include "access/genam.h"
#include "access/commit_ts.h"
+#include "access/htup_details.h"
#include "access/table.h"

Fixed in the attached. Apart from this I changed multiple comments to
make those clear. One notable change is, I moved the newly added
boolean after localindexoid as it reads better there because then we
don't need to forward reference the fields. For back-branches, if it
needs to be moved to an earlier location then we can do that in those
versions but for HEAD and 19, the new location seems better.
Also, shall we keep just one test, say Drop Index Concurrently instead
of two as both tests do the same thing in a slightly different way? I
have not done that but if you agree please update the patch
accordingly.

With Regards,
Amit Kapila.

When the apply worker searches the local relation by index, it can take
the first match as the row only if the index is the relation's replica
identity or primary key. Otherwise every match has to be compared with the
search slot, which holds a complete row only under REPLICA IDENTITY FULL.
Only the index OID was saved, so the scan worked this out a second time
from the catalogs, and the two answers can differ. Apply holds only
RowExclusiveLock, which doesn't conflict with DROP INDEX CONCURRENTLY or
REINDEX CONCURRENTLY, so either can demote the chosen index in between.
Nothing matches, so the change is silently dropped as an update_missing
conflict, and assert-enabled builds fail.

Fix this by recording the answer as idxisreplident in the relation map
entry and passing the entry down to FindReplTupleInLocalRel(), so it is
settled once.

Oversight in 89e46da.

Author: Mikhail Nikalayeu <mihailnikalayeu@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: Zhijie Hou <houzj.fnst@fujitsu.com>
Discussion: https://postgr.es/m/CADzfLwUJovFcnknCC9wjZKECX9xecgnGzC2r2TMV8h4QDD_jwQ@mail.gmail.com
Backpatch-through: 16, where it was introduced
@pg-hub-mirror

pg-hub-mirror Bot commented Sep 18, 2026

Copy link
Copy Markdown
Author

Earlier design discussion: Discussion #61

@pg-hub-mirror pg-hub-mirror Bot added area:storage Storage, access methods, buffers, or I/O source:pgsql-hackers Mirrored from pgsql-hackers type:patch Mail thread contains a PostgreSQL patch area:testing Tests and buildfarm area:replication Physical or logical replication labels Sep 18, 2026
@pg-hub-mirror pg-hub-mirror Bot locked and limited conversation to collaborators Sep 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area:replication Physical or logical replication area:storage Storage, access methods, buffers, or I/O area:testing Tests and buildfarm source:pgsql-hackers Mirrored from pgsql-hackers type:patch Mail thread contains a PostgreSQL patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant