Skip to content

Commit f199436

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 68d3585 commit f199436

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
@@ -317,9 +317,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
317317
PgStat_Counter startreadtime = 0,
318318
startwritetime = 0;
319319
WalUsage startwalusage = pgWalUsage;
320-
int64 StartPageHit = VacuumPageHit,
321-
StartPageMiss = VacuumPageMiss,
322-
StartPageDirty = VacuumPageDirty;
320+
BufferUsage startbufferusage = pgBufferUsage;
323321
ErrorContextCallback errcallback;
324322
char **indnames = NULL;
325323

@@ -611,18 +609,18 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
611609
long secs_dur;
612610
int usecs_dur;
613611
WalUsage walusage;
612+
BufferUsage bufferusage;
614613
StringInfoData buf;
615614
char *msgfmt;
616615
int32 diff;
617-
int64 PageHitOp = VacuumPageHit - StartPageHit,
618-
PageMissOp = VacuumPageMiss - StartPageMiss,
619-
PageDirtyOp = VacuumPageDirty - StartPageDirty;
620616
double read_rate = 0,
621617
write_rate = 0;
622618

623619
TimestampDifference(starttime, endtime, &secs_dur, &usecs_dur);
624620
memset(&walusage, 0, sizeof(WalUsage));
625621
WalUsageAccumDiff(&walusage, &pgWalUsage, &startwalusage);
622+
memset(&bufferusage, 0, sizeof(BufferUsage));
623+
BufferUsageAccumDiff(&bufferusage, &pgBufferUsage, &startbufferusage);
626624

627625
initStringInfo(&buf);
628626
if (verbose)
@@ -749,18 +747,18 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
749747
}
750748
if (secs_dur > 0 || usecs_dur > 0)
751749
{
752-
read_rate = (double) BLCKSZ * PageMissOp / (1024 * 1024) /
753-
(secs_dur + usecs_dur / 1000000.0);
754-
write_rate = (double) BLCKSZ * PageDirtyOp / (1024 * 1024) /
755-
(secs_dur + usecs_dur / 1000000.0);
750+
read_rate = (double) BLCKSZ * (bufferusage.shared_blks_read + bufferusage.local_blks_read) /
751+
(1024 * 1024) / (secs_dur + usecs_dur / 1000000.0);
752+
write_rate = (double) BLCKSZ * (bufferusage.shared_blks_dirtied + bufferusage.local_blks_dirtied) /
753+
(1024 * 1024) / (secs_dur + usecs_dur / 1000000.0);
756754
}
757755
appendStringInfo(&buf, _("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"),
758756
read_rate, write_rate);
759757
appendStringInfo(&buf,
760758
_("buffer usage: %lld hits, %lld misses, %lld dirtied\n"),
761-
(long long) PageHitOp,
762-
(long long) PageMissOp,
763-
(long long) PageDirtyOp);
759+
(long long) (bufferusage.shared_blks_hit + bufferusage.local_blks_hit),
760+
(long long) (bufferusage.shared_blks_read + bufferusage.local_blks_read),
761+
(long long) (bufferusage.shared_blks_dirtied + bufferusage.local_blks_dirtied));
764762
appendStringInfo(&buf,
765763
_("WAL usage: %lld records, %lld full page images, %llu bytes\n"),
766764
(long long) walusage.wal_records,

0 commit comments

Comments
 (0)