]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix waiting in RegisterSyncRequest().
authorThomas Munro <tmunro@postgresql.org>
Wed, 16 Mar 2022 02:38:13 +0000 (15:38 +1300)
committerThomas Munro <tmunro@postgresql.org>
Wed, 16 Mar 2022 02:38:13 +0000 (15:38 +1300)
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

doc/src/sgml/monitoring.sgml
src/backend/postmaster/pgstat.c
src/backend/storage/sync/sync.c
src/include/pgstat.h

index af3e9a71656b90d81197a6bb5c7d97cbc2942d5e..fb59bd9981ac3bc96ae416afd86df18da11ec3ac 100644 (file)
@@ -1483,7 +1483,7 @@ postgres   27093  0.0  0.0  30096  2752 ?        Ss   11:34   0:00 postgres: ser
          <entry>Waiting for confirmation from remote server during synchronous replication.</entry>
         </row>
         <row>
-         <entry morerows="2"><literal>Timeout</literal></entry>
+         <entry morerows="3"><literal>Timeout</literal></entry>
          <entry><literal>BaseBackupThrottle</literal></entry>
          <entry>Waiting during base backup when throttling activity.</entry>
         </row>
@@ -1495,6 +1495,11 @@ postgres   27093  0.0  0.0  30096  2752 ?        Ss   11:34   0:00 postgres: ser
          <entry><literal>RecoveryApplyDelay</literal></entry>
          <entry>Waiting to apply WAL at recovery because it is delayed.</entry>
         </row>
+        <row>
+         <entry><literal>RegisterSyncRequest</literal></entry>
+         <entry>Waiting while sending synchronization requests to the
+         checkpointer, because the request queue is full.</entry>
+        </row>
         <row>
          <entry morerows="67"><literal>IO</literal></entry>
          <entry><literal>BufFileRead</literal></entry>
index a5d97784cf968f3196c3b026ffaee21a7dda9a85..e03233ae7d0c744eb46ef7ba4a83a152da4c6b6e 100644 (file)
@@ -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 */
        }
 
index aff3e885f36553543c1f29870b591511dd20bc4f..a67dc591e0e0c54ccfd4732bb1e7ff32e33dfc40 100644 (file)
@@ -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;
index d10c270e60d5b3a1a6bd6de1db7d8ef771ca6478..a044d83ed089cf5ad6b3d2861ab585ec6fdc4e4b 100644 (file)
@@ -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;
 
 /* ----------