From: Thomas Munro Date: Wed, 16 Mar 2022 02:38:13 +0000 (+1300) Subject: Fix waiting in RegisterSyncRequest(). X-Git-Tag: REL_12_11~61 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=368ffdeee422e8df57330a290f32b986291c2584;p=thirdparty%2Fpostgresql.git Fix waiting in RegisterSyncRequest(). If we run out of space in the checkpointer sync request queue (which is hopefully rare on real systems, but common with very small buffer pool), we wait for it to drain. While waiting, we should report that as a wait event so that users know what is going on, and also handle postmaster death, since otherwise the loop might never terminate if the checkpointer has exited. Back-patch to 12. Although the problem exists in earlier releases too, the code is structured differently before 12 so I haven't gone any further for now, in the absence of field complaints. Reported-by: Andres Freund Reviewed-by: Andres Freund Discussion: https://postgr.es/m/20220226213942.nb7uvb2pamyu26dj%40alap3.anarazel.de --- diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index af3e9a71656..fb59bd9981a 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -1483,7 +1483,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser Waiting for confirmation from remote server during synchronous replication. - Timeout + Timeout BaseBackupThrottle Waiting during base backup when throttling activity. @@ -1495,6 +1495,11 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser RecoveryApplyDelay Waiting to apply WAL at recovery because it is delayed. + + RegisterSyncRequest + Waiting while sending synchronization requests to the + checkpointer, because the request queue is full. + IO BufFileRead diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index a5d97784cf9..e03233ae7d0 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -3889,6 +3889,9 @@ pgstat_get_wait_timeout(WaitEventTimeout w) case WAIT_EVENT_RECOVERY_APPLY_DELAY: event_name = "RecoveryApplyDelay"; break; + case WAIT_EVENT_REGISTER_SYNC_REQUEST: + event_name = "RegisterSyncRequest"; + break; /* no default case, so that compiler will warn */ } diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c index aff3e885f36..a67dc591e0e 100644 --- a/src/backend/storage/sync/sync.c +++ b/src/backend/storage/sync/sync.c @@ -27,6 +27,7 @@ #include "postmaster/bgwriter.h" #include "storage/bufmgr.h" #include "storage/ipc.h" +#include "storage/latch.h" #include "storage/md.h" #include "utils/hsearch.h" #include "utils/memutils.h" @@ -569,7 +570,8 @@ RegisterSyncRequest(const FileTag *ftag, SyncRequestType type, if (ret || (!ret && !retryOnError)) break; - pg_usleep(10000L); + WaitLatch(NULL, WL_EXIT_ON_PM_DEATH | WL_TIMEOUT, 10, + WAIT_EVENT_REGISTER_SYNC_REQUEST); } return ret; diff --git a/src/include/pgstat.h b/src/include/pgstat.h index d10c270e60d..a044d83ed08 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -867,7 +867,8 @@ typedef enum { WAIT_EVENT_BASE_BACKUP_THROTTLE = PG_WAIT_TIMEOUT, WAIT_EVENT_PG_SLEEP, - WAIT_EVENT_RECOVERY_APPLY_DELAY + WAIT_EVENT_RECOVERY_APPLY_DELAY, + WAIT_EVENT_REGISTER_SYNC_REQUEST } WaitEventTimeout; /* ----------