Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5e6368b

Browse files
committed
Wake up for latches in CheckpointWriteDelay().
The checkpointer shouldn't ignore its latch. Other backends may be waiting for it to drain the request queue. Hopefully real systems don't have a full queue often, but the condition is reached easily when shared_buffers is small. This involves defining a new wait event, which will appear in the pg_stat_activity view often due to spread checkpoints. Back-patch only to 14. Even though the problem exists in earlier branches too, it's hard to hit there. In 14 we stopped using signal handlers for latches on Linux, *BSD and macOS, which were previously hiding this problem by interrupting the sleep (though not reliably, as the signal could arrive before the sleep begins; precisely the problem latches address). Reported-by: Andres Freund <andres@anarazel.de> Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/20220226213942.nb7uvb2pamyu26dj%40alap3.anarazel.de
1 parent a56e7b6 commit 5e6368b

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

doc/src/sgml/monitoring.sgml

+4
Original file line numberDiff line numberDiff line change
@@ -2235,6 +2235,10 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
22352235
<entry><literal>BaseBackupThrottle</literal></entry>
22362236
<entry>Waiting during base backup when throttling activity.</entry>
22372237
</row>
2238+
<row>
2239+
<entry><literal>CheckpointerWriteDelay</literal></entry>
2240+
<entry>Waiting between writes while performing a checkpoint.</entry>
2241+
</row>
22382242
<row>
22392243
<entry><literal>PgSleep</literal></entry>
22402244
<entry>Waiting due to a call to <function>pg_sleep</function> or

src/backend/postmaster/checkpointer.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ CheckpointerMain(void)
484484
}
485485

486486
ckpt_active = false;
487+
488+
/* We may have received an interrupt during the checkpoint. */
489+
HandleCheckpointerInterrupts();
487490
}
488491

489492
/* Check for archive_timeout and switch xlog files if necessary. */
@@ -726,7 +729,10 @@ CheckpointWriteDelay(int flags, double progress)
726729
* Checkpointer and bgwriter are no longer related so take the Big
727730
* Sleep.
728731
*/
729-
pg_usleep(100000L);
732+
WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH | WL_TIMEOUT,
733+
100,
734+
WAIT_EVENT_CHECKPOINT_WRITE_DELAY);
735+
ResetLatch(MyLatch);
730736
}
731737
else if (--absorb_counter <= 0)
732738
{

src/backend/utils/activity/wait_event.c

+3
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,9 @@ pgstat_get_wait_timeout(WaitEventTimeout w)
485485
case WAIT_EVENT_BASE_BACKUP_THROTTLE:
486486
event_name = "BaseBackupThrottle";
487487
break;
488+
case WAIT_EVENT_CHECKPOINT_WRITE_DELAY:
489+
event_name = "CheckpointWriteDelay";
490+
break;
488491
case WAIT_EVENT_PG_SLEEP:
489492
event_name = "PgSleep";
490493
break;

src/include/utils/wait_event.h

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ typedef enum
141141
typedef enum
142142
{
143143
WAIT_EVENT_BASE_BACKUP_THROTTLE = PG_WAIT_TIMEOUT,
144+
WAIT_EVENT_CHECKPOINT_WRITE_DELAY,
144145
WAIT_EVENT_PG_SLEEP,
145146
WAIT_EVENT_RECOVERY_APPLY_DELAY,
146147
WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL,

0 commit comments

Comments
 (0)