Skip to content

Commit 5cd72cc

Browse files
Fix parallel vacuum buffer usage reporting.
A parallel worker's buffer usage is accumulated to its pgBufferUsage and then is accumulated into the leader's one at the end of the parallel vacuum. However, since the leader process used to use dedicated VacuumPage{Hit, Miss, Dirty} globals for the buffer usage reporting, the worker's buffer usage was not included, leading to an incorrect buffer usage report. To fix the problem, this commit makes vacuum use pgBufferUsage instruments for buffer usage reporting instead of VacuumPage{Hit, Miss, Dirty} globals. These global variables are still used by ANALYZE command and autoanalyze. This also fixes the buffer usage report of vacuuming on temporary tables, since the buffers dirtied by MarkLocalBufferDirty() were not tracked by the VacuumPageDirty variable. Parallel vacuum was introduced in 13, but the buffer usage reporting for VACUUM command with the VERBOSE option was implemented in 15. So backpatch to 15. Reported-by: Anthonin Bonnefoy Author: Anthonin Bonnefoy Reviewed-by: Alena Rybakina, Masahiko Sawada Discussion: https://postgr.es/m/CAO6_XqrQk+QZQcYs_C6nk0cMfHuUWk85vT9CrcA1NffFbAVE2A@mail.gmail.com Backpatch-through: 15
1 parent 2800fbb commit 5cd72cc

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/backend/access/heap/vacuumlazy.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
309309
PgStat_Counter startreadtime = 0,
310310
startwritetime = 0;
311311
WalUsage startwalusage = pgWalUsage;
312-
int64 StartPageHit = VacuumPageHit,
313-
StartPageMiss = VacuumPageMiss,
314-
StartPageDirty = VacuumPageDirty;
312+
BufferUsage startbufferusage = pgBufferUsage;
315313
ErrorContextCallback errcallback;
316314
char **indnames = NULL;
317315

@@ -604,18 +602,18 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
604602
long secs_dur;
605603
int usecs_dur;
606604
WalUsage walusage;
605+
BufferUsage bufferusage;
607606
StringInfoData buf;
608607
char *msgfmt;
609608
int32 diff;
610-
int64 PageHitOp = VacuumPageHit - StartPageHit,
611-
PageMissOp = VacuumPageMiss - StartPageMiss,
612-
PageDirtyOp = VacuumPageDirty - StartPageDirty;
613609
double read_rate = 0,
614610
write_rate = 0;
615611

616612
TimestampDifference(starttime, endtime, &secs_dur, &usecs_dur);
617613
memset(&walusage, 0, sizeof(WalUsage));
618614
WalUsageAccumDiff(&walusage, &pgWalUsage, &startwalusage);
615+
memset(&bufferusage, 0, sizeof(BufferUsage));
616+
BufferUsageAccumDiff(&bufferusage, &pgBufferUsage, &startbufferusage);
619617

620618
initStringInfo(&buf);
621619
if (verbose)
@@ -742,18 +740,18 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
742740
}
743741
if (secs_dur > 0 || usecs_dur > 0)
744742
{
745-
read_rate = (double) BLCKSZ * PageMissOp / (1024 * 1024) /
746-
(secs_dur + usecs_dur / 1000000.0);
747-
write_rate = (double) BLCKSZ * PageDirtyOp / (1024 * 1024) /
748-
(secs_dur + usecs_dur / 1000000.0);
743+
read_rate = (double) BLCKSZ * (bufferusage.shared_blks_read + bufferusage.local_blks_read) /
744+
(1024 * 1024) / (secs_dur + usecs_dur / 1000000.0);
745+
write_rate = (double) BLCKSZ * (bufferusage.shared_blks_dirtied + bufferusage.local_blks_dirtied) /
746+
(1024 * 1024) / (secs_dur + usecs_dur / 1000000.0);
749747
}
750748
appendStringInfo(&buf, _("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"),
751749
read_rate, write_rate);
752750
appendStringInfo(&buf,
753751
_("buffer usage: %lld hits, %lld misses, %lld dirtied\n"),
754-
(long long) PageHitOp,
755-
(long long) PageMissOp,
756-
(long long) PageDirtyOp);
752+
(long long) (bufferusage.shared_blks_hit + bufferusage.local_blks_hit),
753+
(long long) (bufferusage.shared_blks_read + bufferusage.local_blks_read),
754+
(long long) (bufferusage.shared_blks_dirtied + bufferusage.local_blks_dirtied));
757755
appendStringInfo(&buf,
758756
_("WAL usage: %lld records, %lld full page images, %llu bytes\n"),
759757
(long long) walusage.wal_records,

0 commit comments

Comments
 (0)