From ec253de1fd2e6002122de80815ac5b963af8277c Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Fri, 9 Sep 2016 11:55:12 +0100 Subject: [PATCH] Fix corruption of 2PC recovery with subxacts Reading 2PC state files during recovery was borked, causing corruptions during recovery. Effect limited to servers with 2PC, subtransactions and recovery/replication. Stas Kelvich, reviewed by Michael Paquier and Pavan Deolasee --- src/backend/access/transam/twophase.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 1323fb508d..5415604993 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1758,8 +1758,9 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p) * need to hold a lock while examining it. We still acquire the * lock to modify it, though. */ - subxids = (TransactionId *) - (buf + MAXALIGN(sizeof(TwoPhaseFileHeader))); + subxids = (TransactionId *) (buf + + MAXALIGN(sizeof(TwoPhaseFileHeader)) + + MAXALIGN(hdr->gidlen)); for (i = 0; i < hdr->nsubxacts; i++) { TransactionId subxid = subxids[i]; @@ -1877,8 +1878,9 @@ StandbyRecoverPreparedTransactions(bool overwriteOK) * Examine subtransaction XIDs ... they should all follow main * XID. */ - subxids = (TransactionId *) - (buf + MAXALIGN(sizeof(TwoPhaseFileHeader))); + subxids = (TransactionId *) (buf + + MAXALIGN(sizeof(TwoPhaseFileHeader)) + + MAXALIGN(hdr->gidlen)); for (i = 0; i < hdr->nsubxacts; i++) { TransactionId subxid = subxids[i];