diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 3d2f04e81db805bf2915206de37377ffb640308b..a7a9fc5d05949d5bf9b23fa7e0834de4e7f68013 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -1391,6 +1391,9 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
 	/* compute latestXid among all children */
 	latestXid = TransactionIdLatest(xid, hdr->nsubxacts, children);
 
+	/* Prevent cancel/die interrupt while cleaning up */
+	HOLD_INTERRUPTS();
+
 	/*
 	 * The order of operations here is critical: make the XLOG entry for
 	 * commit or abort, then mark the transaction committed or aborted in
@@ -1478,6 +1481,8 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
 	RemoveGXact(gxact);
 	MyLockedGxact = NULL;
 
+	RESUME_INTERRUPTS();
+
 	pfree(buf);
 }