diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index b420aef5ab..2c3e262224 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1485,6 +1485,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit) GlobalTransaction gxact; PGPROC *proc; TransactionId xid; + bool ondisk; char *buf; char *bufptr; TwoPhaseFileHeader *hdr; @@ -1637,6 +1638,12 @@ FinishPreparedTransaction(const char *gid, bool isCommit) PredicateLockTwoPhaseFinish(xid, isCommit); + /* + * Read this value while holding the two-phase lock, as the on-disk 2PC + * file is physically removed after the lock is released. + */ + ondisk = gxact->ondisk; + /* Clear shared memory state */ RemoveGXact(gxact); @@ -1652,7 +1659,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit) /* * And now we can clean up any files we may have left. */ - if (gxact->ondisk) + if (ondisk) RemoveTwoPhaseFile(xid, true); MyLockedGxact = NULL;