diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3b6938135ac..8a66896b5cf 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -2422,10 +2422,11 @@ LockBufferForCleanup(Buffer buffer) /* Wait to be signaled by UnpinBuffer() */ if (InHotStandby) { - /* Share the bufid that Startup process waits on */ + /* Publish the bufid that Startup process waits on */ SetStartupBufferPinWaitBufId(buffer - 1); /* Set alarm and then wait to be signaled by UnpinBuffer() */ ResolveRecoveryConflictWithBufferPin(); + /* Reset the published bufid */ SetStartupBufferPinWaitBufId(-1); } else diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index c9993a79dba..2608fea9451 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -179,6 +179,9 @@ InitProcGlobal(void) */ ProcGlobal->freeProcs = NULL; ProcGlobal->autovacFreeProcs = NULL; + ProcGlobal->startupProc = NULL; + ProcGlobal->startupProcPid = 0; + ProcGlobal->startupBufferPinWaitBufId = -1; ProcGlobal->spins_per_delay = DEFAULT_SPINS_PER_DELAY; @@ -487,7 +490,6 @@ PublishStartupProcessInformation(void) procglobal->startupProc = MyProc; procglobal->startupProcPid = MyProcPid; - procglobal->startupBufferPinWaitBufId = 0; SpinLockRelease(ProcStructLock); } @@ -514,14 +516,10 @@ SetStartupBufferPinWaitBufId(int bufid) int GetStartupBufferPinWaitBufId(void) { - int bufid; - /* use volatile pointer to prevent code rearrangement */ volatile PROC_HDR *procglobal = ProcGlobal; - bufid = procglobal->startupBufferPinWaitBufId; - - return bufid; + return procglobal->startupBufferPinWaitBufId; } /* diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index f77c4d3fc29..fe35db13dc3 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -145,7 +145,7 @@ typedef struct PROC_HDR /* The proc of the Startup process, since not in ProcArray */ PGPROC *startupProc; int startupProcPid; - /* Buffer id of the buffer that Startup process waits for pin on */ + /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ int startupBufferPinWaitBufId; } PROC_HDR;