diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 60e3ae6e506..fd5a9f66fa1 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -9311,6 +9311,12 @@ CreateCheckPoint(int flags) { do { + /* + * Keep absorbing fsync requests while we wait. There could even + * be a deadlock if we don't, if the process that prevents the + * checkpoint is trying to add a request to the queue. + */ + AbsorbSyncRequests(); pg_usleep(10000L); /* wait for 10 msec */ } while (HaveVirtualXIDsDelayingChkpt(vxids, nvxids)); } @@ -9323,6 +9329,7 @@ CreateCheckPoint(int flags) { do { + AbsorbSyncRequests(); pg_usleep(10000L); /* wait for 10 msec */ } while (HaveVirtualXIDsDelayingChkptEnd(vxids, nvxids)); } diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index 86996750dcd..3b1049faef6 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -1174,6 +1174,10 @@ CompactCheckpointerRequestQueue(void) /* must hold CheckpointerCommLock in exclusive mode */ Assert(LWLockHeldByMe(CheckpointerCommLock)); + /* Avoid memory allocations in a critical section. */ + if (CritSectionCount > 0) + return false; + /* Initialize skip_slot array */ skip_slot = palloc0(sizeof(bool) * CheckpointerShmem->num_requests);