Skip to content

Commit 2bef57e

Browse files
committed
Fix fractional vacuum_cost_delay.
Commit 4753ef3 changed vacuum_delay_point() to use the WaitLatch() API, to fix the problem that vacuum could keep running for a very long time after the postmaster died. Unfortunately, that broke commit caf626b's support for fractional vacuum_cost_delay, which shipped in PostgreSQL 12. WaitLatch() works in whole milliseconds. For now, revert the change from commit 4753ef3, but add an explicit check for postmaster death. That's an extra system call on systems other than Linux and FreeBSD, but that overhead doesn't matter much considering that we willingly went to sleep and woke up again. (In later work, we might add higher resolution timeouts to the latch API so that we could do this with our standard programming pattern, but that wouldn't be back-patched.) Back-patch to 14, where commit 4753ef3 arrived. Reported-by: Melanie Plageman <melanieplageman@gmail.com> Discussion: https://postgr.es/m/CAAKRu_b-q0hXCBUCAATh0Z4Zi6UkiC0k2DFgoD3nC-r3SkR3tg%40mail.gmail.com
1 parent 9b6e0b9 commit 2bef57e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/backend/commands/vacuum.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "postmaster/bgworker_internals.h"
4646
#include "storage/bufmgr.h"
4747
#include "storage/lmgr.h"
48+
#include "storage/pmsignal.h"
4849
#include "storage/proc.h"
4950
#include "storage/procarray.h"
5051
#include "utils/acl.h"
@@ -2171,11 +2172,18 @@ vacuum_delay_point(void)
21712172
if (msec > VacuumCostDelay * 4)
21722173
msec = VacuumCostDelay * 4;
21732174

2174-
(void) WaitLatch(MyLatch,
2175-
WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
2176-
msec,
2177-
WAIT_EVENT_VACUUM_DELAY);
2178-
ResetLatch(MyLatch);
2175+
pgstat_report_wait_start(WAIT_EVENT_VACUUM_DELAY);
2176+
pg_usleep(msec * 1000);
2177+
pgstat_report_wait_end();
2178+
2179+
/*
2180+
* We don't want to ignore postmaster death during very long vacuums
2181+
* with vacuum_cost_delay configured. We can't use the usual
2182+
* WaitLatch() approach here because we want microsecond-based sleep
2183+
* durations above.
2184+
*/
2185+
if (IsUnderPostmaster && !PostmasterIsAlive())
2186+
exit(1);
21792187

21802188
VacuumCostBalance = 0;
21812189

0 commit comments

Comments
 (0)