]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Prevent tuples to be marked as dead in subtransactions on standbys
authorMichael Paquier <michael@paquier.xyz>
Tue, 12 Dec 2023 16:05:36 +0000 (17:05 +0100)
committerMichael Paquier <michael@paquier.xyz>
Tue, 12 Dec 2023 16:05:36 +0000 (17:05 +0100)
Dead tuples are ignored and are not marked as dead during recovery, as
it can lead to MVCC issues on a standby because its xmin may not match
with the primary.  This information is tracked by a field called
"xactStartedInRecovery" in the transaction state data, switched on when
starting a transaction in recovery.

Unfortunately, this information was not correctly tracked when starting
a subtransaction, because the transaction state used for the
subtransaction did not update "xactStartedInRecovery" based on the state
of its parent.  This would cause index scans done in subtransactions to
return inconsistent data, depending on how the xmin of the primary
and/or the standby evolved.

This is broken since the introduction of hot standby in efc16ea52067, so
backpatch all the way down.

Author: Fei Changhong
Reviewed-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/tencent_C4D907A5093C071A029712E73B43C6512706@qq.com
Backpatch-through: 12

src/backend/access/transam/xact.c

index 08b118da36610c0efc0531f9715ce3b18511b790..12854dfad84a47d8d192eaeb1b39f0731457a678 100644 (file)
@@ -5155,6 +5155,7 @@ PushTransaction(void)
        s->blockState = TBLOCK_SUBBEGIN;
        GetUserIdAndSecContext(&s->prevUser, &s->prevSecContext);
        s->prevXactReadOnly = XactReadOnly;
+       s->startedInRecovery = p->startedInRecovery;
        s->parallelModeLevel = 0;
 
        CurrentTransactionState = s;