aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2022-03-16 15:37:15 +1300
committerThomas Munro <tmunro@postgresql.org>2022-03-16 15:37:15 +1300
commitcfdb303be756d846031ba1c1d1ff2cae39a62c15 (patch)
tree079f0faab13bce0ae2fb6814198edfe1df2772d4 /src
parentd3a9b83c30b62898f6823d127c6b6ddef98f7cba (diff)
downloadpostgresql-cfdb303be756d846031ba1c1d1ff2cae39a62c15.tar.gz
postgresql-cfdb303be756d846031ba1c1d1ff2cae39a62c15.zip
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 <andres@anarazel.de> Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/20220226213942.nb7uvb2pamyu26dj%40alap3.anarazel.de
Diffstat (limited to 'src')
-rw-r--r--src/backend/postmaster/pgstat.c3
-rw-r--r--src/backend/storage/sync/sync.c4
-rw-r--r--src/include/pgstat.h3
3 files changed, 8 insertions, 2 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 24e54d6766f..1e2064456b0 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -3919,6 +3919,9 @@ pgstat_get_wait_timeout(WaitEventTimeout w)
case WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL:
event_name = "RecoveryRetrieveRetryInterval";
break;
+ case WAIT_EVENT_REGISTER_SYNC_REQUEST:
+ event_name = "RegisterSyncRequest";
+ break;
case WAIT_EVENT_VACUUM_DELAY:
event_name = "VacuumDelay";
break;
diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c
index 4ce2e687d3c..d8c02220a29 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/inval.h"
@@ -585,7 +586,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 c55dc1481ca..46fa42c2013 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -902,7 +902,8 @@ typedef enum
WAIT_EVENT_PG_SLEEP,
WAIT_EVENT_RECOVERY_APPLY_DELAY,
WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL,
- WAIT_EVENT_VACUUM_DELAY
+ WAIT_EVENT_VACUUM_DELAY,
+ WAIT_EVENT_REGISTER_SYNC_REQUEST
} WaitEventTimeout;
/* ----------