pgsql: Fix duplicate transaction replay during pg_createsubscriber.

From: Amit Kapila <akapila(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix duplicate transaction replay during pg_createsubscriber.
Date: 2025-07-24 09:20:48
Message-ID: E1ues88-000UeU-02@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix duplicate transaction replay during pg_createsubscriber.

Previously, the tool could replay the same transaction twice, once during
recovery, then again during replication after the subscriber was set up.

This occurred because the same recovery_target_lsn was used both to
finalize recovery and to start replication. If
recovery_target_inclusive = true, the transaction at that LSN would be
applied during recovery and then sent again by the publisher leading to
duplication.

To prevent this, we now set recovery_target_inclusive = false. This
ensures the transaction at recovery_target_lsn is not reapplied during
recovery, avoiding duplication when replication begins.

Bug #18897
Reported-by: Zane Duffield <duffieldzane(at)gmail(dot)com>
Author: Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>
Reviewed-by: vignesh C <vignesh21(at)gmail(dot)com>
Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Backpatch-through: 17, where it was introduced
Discussion: https://postgr.es/m/18897-d3db67535860dddb@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e1c3654839e464957675344a1e949489d98b103b

Modified Files
--------------
src/bin/pg_basebackup/pg_createsubscriber.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Nathan Bossart 2025-07-24 15:14:00 pgsql: Fix return value of visibilitymap_get_status().
Previous Message Michael Paquier 2025-07-24 06:42:43 pgsql: Introduce field tracking cached plan type in PlannedStmt