diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 330e058c5f28a..8dcdf5a764647 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7094,6 +7094,13 @@ 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(); + pgstat_report_wait_start(WAIT_EVENT_CHECKPOINT_DELAY_START); pg_usleep(10000L); /* wait for 10 msec */ pgstat_report_wait_end(); @@ -7109,6 +7116,8 @@ CreateCheckPoint(int flags) { do { + AbsorbSyncRequests(); + pgstat_report_wait_start(WAIT_EVENT_CHECKPOINT_DELAY_COMPLETE); pg_usleep(10000L); /* wait for 10 msec */ pgstat_report_wait_end(); diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index 3c68a9904db5e..199f008bcda81 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -1169,6 +1169,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);