diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 9a8257fcaf..ae23f407b9 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1505,6 +1505,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit) GlobalTransaction gxact; PGPROC *proc; TransactionId xid; + bool ondisk; char *buf; char *bufptr; TwoPhaseFileHeader *hdr; @@ -1657,6 +1658,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); @@ -1672,7 +1679,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;