Skip to content

Commit 7068538

Browse files
committed
Use WaitLatch() instead of pg_usleep() at end-of-vacuum truncation
This has the advantage to make a process more responsive when the postmaster dies, even if the wait time was rather limited as there was only a 50ms timeout here. Another advantage of this change is for monitoring, as we gain a new wait event for the end-of-vacuum truncation. Author: Bharath Rupireddy Reviewed-by: Aleksander Alekseev, Thomas Munro, Michael Paquier Discussion: https://postgr.es/m/CALj2ACU4AdPCq6NLfcA-ZGwX7pPCK5FgEj-CAU0xCKzkASSy_A@mail.gmail.com
1 parent a2595e0 commit 7068538

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

doc/src/sgml/monitoring.sgml

+5
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,11 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
22422242
<entry><literal>VacuumDelay</literal></entry>
22432243
<entry>Waiting in a cost-based vacuum delay point.</entry>
22442244
</row>
2245+
<row>
2246+
<entry><literal>VacuumTruncate</literal></entry>
2247+
<entry>Waiting to acquire an exclusive lock to truncate off any
2248+
empty pages at the end of a table vacuumed.</entry>
2249+
</row>
22452250
</tbody>
22462251
</tgroup>
22472252
</table>

src/backend/access/heap/vacuumlazy.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -3236,7 +3236,11 @@ lazy_truncate_heap(LVRelState *vacrel)
32363236
return;
32373237
}
32383238

3239-
pg_usleep(VACUUM_TRUNCATE_LOCK_WAIT_INTERVAL * 1000L);
3239+
(void) WaitLatch(MyLatch,
3240+
WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
3241+
VACUUM_TRUNCATE_LOCK_WAIT_INTERVAL,
3242+
WAIT_EVENT_VACUUM_TRUNCATE);
3243+
ResetLatch(MyLatch);
32403244
}
32413245

32423246
/*

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_VACUUM_DELAY:
486486
event_name = "VacuumDelay";
487487
break;
488+
case WAIT_EVENT_VACUUM_TRUNCATE:
489+
event_name = "VacuumTruncate";
490+
break;
488491
/* no default case, so that compiler will warn */
489492
}
490493

src/include/utils/wait_event.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ typedef enum
140140
WAIT_EVENT_PG_SLEEP,
141141
WAIT_EVENT_RECOVERY_APPLY_DELAY,
142142
WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL,
143-
WAIT_EVENT_VACUUM_DELAY
143+
WAIT_EVENT_VACUUM_DELAY,
144+
WAIT_EVENT_VACUUM_TRUNCATE
144145
} WaitEventTimeout;
145146

146147
/* ----------

0 commit comments

Comments
 (0)