diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 0d57fb25c27..08e7e4ccd2e 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1487,6 +1487,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit) PGPROC *proc; PGXACT *pgxact; TransactionId xid; + bool ondisk; char *buf; char *bufptr; TwoPhaseFileHeader *hdr; @@ -1621,6 +1622,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); @@ -1636,7 +1643,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;