Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0d34314

Browse files
committed
Add logging for excessive ProcSignalBarrier waits.
To enable diagnosis of systems that are not processing ProcSignalBarrier requests promptly, add a LOG message every 5 seconds if we seem to be wedged. Although you could already see this state as a wait event in pg_stat_activity, the log message also shows the PID of the process that is preventing progress. Also add DEBUG1 logging around the whole wait loop. Reviewed-by: Robert Haas <[email protected]> Discussion: https://postgr.es/m/CA%2BTgmoYJ03r5359gQutRGP9BtigYCg3_UskcmnVjBf-QO3-0pQ%40mail.gmail.com
1 parent f95d53e commit 0d34314

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/backend/storage/ipc/procsignal.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,11 @@ WaitForProcSignalBarrier(uint64 generation)
393393
{
394394
Assert(generation <= pg_atomic_read_u64(&ProcSignal->psh_barrierGeneration));
395395

396+
elog(DEBUG1,
397+
"waiting for all backends to process ProcSignalBarrier generation "
398+
UINT64_FORMAT,
399+
generation);
400+
396401
for (int i = NumProcSignalSlots - 1; i >= 0; i--)
397402
{
398403
ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
@@ -407,13 +412,22 @@ WaitForProcSignalBarrier(uint64 generation)
407412
oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration);
408413
while (oldval < generation)
409414
{
410-
ConditionVariableSleep(&slot->pss_barrierCV,
411-
WAIT_EVENT_PROC_SIGNAL_BARRIER);
415+
if (ConditionVariableTimedSleep(&slot->pss_barrierCV,
416+
5000,
417+
WAIT_EVENT_PROC_SIGNAL_BARRIER))
418+
ereport(LOG,
419+
(errmsg("still waiting for backend with PID %lu to accept ProcSignalBarrier",
420+
(unsigned long) slot->pss_pid)));
412421
oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration);
413422
}
414423
ConditionVariableCancelSleep();
415424
}
416425

426+
elog(DEBUG1,
427+
"finished waiting for all backends to process ProcSignalBarrier generation "
428+
UINT64_FORMAT,
429+
generation);
430+
417431
/*
418432
* The caller is probably calling this function because it wants to read
419433
* the shared state or perform further writes to shared state once all

0 commit comments

Comments
 (0)