pgsql: Prevent tuples to be marked as dead in subtransactions on standb

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Prevent tuples to be marked as dead in subtransactions on standb
Date: 2023-12-12 16:06:51
Message-ID: E1rD5HX-009rzG-AO@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Prevent tuples to be marked as dead in subtransactions on standbys

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

Branch
------
REL_15_STABLE

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

Modified Files
--------------
src/backend/access/transam/xact.c | 1 +
1 file changed, 1 insertion(+)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Daniel Gustafsson 2023-12-13 10:44:50 pgsql: docs: Fix typo in pg_stat_statements documentation
Previous Message Daniel Gustafsson 2023-12-12 11:27:47 pgsql: Fix typo in comment

Browse pgsql-hackers by date

  From Date Subject
Next Message Euler Taveira 2023-12-12 19:54:32 Re: Move walreceiver state assignment (to WALRCV_STREAMING) in WalReceiverMain()
Previous Message Drouvot, Bertrand 2023-12-12 15:58:58 Move walreceiver state assignment (to WALRCV_STREAMING) in WalReceiverMain()