postgres.git / summary / log / commit / refs
commit 223a946804aafeefc6cb26de276776eec576547d
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Thu Apr 23 18:25:44 2015 +0000
First released in: 9.5.0, 9.0.20, 9.1.16, 9.2.11, 9.3.7, 9.4.2
Fix deadlock at startup, if max_prepared_transactions is too small.
When the startup process recovers transactions by scanning pg_twophase
directory, it should clear MyLockedGxact after it's done processing each
transaction. Like we do during normal operation, at PREPARE TRANSACTION.
Otherwise, if the startup process exits due to an error, it will try to
clear the locking_backend field of the last recovered transaction. That's
usually harmless, but if the error happens in MarkAsPreparing, while
holding TwoPhaseStateLock, the shmem-exit hook will try to acquire
TwoPhaseStateLock again, and deadlock with itself.
This fixes bug #13128 reported by Grant McAlister. The bug was introduced
by commit bb38fb0d, so backpatch to all supported versions like that
commit.
src/backend/access/transam/twophase.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index c29f86bec3a..a5c9ee8e865 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -1998,6 +1998,12 @@ RecoverPreparedTransactions(void)
if (InHotStandby)
StandbyReleaseLockTree(xid, hdr->nsubxacts, subxids);
+ /*
+ * We're done with recovering this transaction. Clear MyLockedGxact,
+ * like we do in PrepareTransaction() during normal operation.
+ */
+ PostPrepare_Twophase();
+
pfree(buf);
}
}
[parent: 5feebfed83fe]