diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index c269cd633c4f2bcd6c5f45741242f598073aecdf..01aa8cb9b818b9d5a326f35f6bb658c6e5a89a9d 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -2055,6 +2055,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);
 		}
 	}