Skip to content

Commit d3609dd

Browse files
Fix multi-table VACUUM VERBOSE accounting.
Per-backend global variables like VacuumPageHit are initialized once per VACUUM command. This was missed by commit 49c9d9f, which unified VACUUM VERBOSE and autovacuum logging. As a result of that oversight, incorrect values were shown when multiple relations were processed by a single VACUUM VERBOSE command. Relations that happened to be processed later on would show "buffer usage:" values that incorrectly included buffer accesses made while processing earlier unrelated relations. The same accesses were counted multiple times. To fix, take initial values for the tracker variables at the start of heap_vacuum_rel(), and report delta values later on.
1 parent 7129a97 commit d3609dd

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/backend/access/heap/vacuumlazy.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,12 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
325325
new_rel_allvisible;
326326
PGRUsage ru0;
327327
TimestampTz starttime = 0;
328-
PgStat_Counter startreadtime = 0;
329-
PgStat_Counter startwritetime = 0;
330-
WalUsage walusage_start = pgWalUsage;
328+
PgStat_Counter startreadtime = 0,
329+
startwritetime = 0;
330+
WalUsage startwalusage = pgWalUsage;
331+
int64 StartPageHit = VacuumPageHit,
332+
StartPageMiss = VacuumPageMiss,
333+
StartPageDirty = VacuumPageDirty;
331334
ErrorContextCallback errcallback;
332335
char **indnames = NULL;
333336

@@ -639,12 +642,15 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
639642
StringInfoData buf;
640643
char *msgfmt;
641644
int32 diff;
645+
int64 PageHitOp = VacuumPageHit - StartPageHit,
646+
PageMissOp = VacuumPageMiss - StartPageMiss,
647+
PageDirtyOp = VacuumPageDirty - StartPageDirty;
642648
double read_rate = 0,
643649
write_rate = 0;
644650

645651
TimestampDifference(starttime, endtime, &secs_dur, &usecs_dur);
646652
memset(&walusage, 0, sizeof(WalUsage));
647-
WalUsageAccumDiff(&walusage, &pgWalUsage, &walusage_start);
653+
WalUsageAccumDiff(&walusage, &pgWalUsage, &startwalusage);
648654

649655
initStringInfo(&buf);
650656
if (verbose)
@@ -763,18 +769,18 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
763769
}
764770
if (secs_dur > 0 || usecs_dur > 0)
765771
{
766-
read_rate = (double) BLCKSZ * VacuumPageMiss / (1024 * 1024) /
772+
read_rate = (double) BLCKSZ * PageMissOp / (1024 * 1024) /
767773
(secs_dur + usecs_dur / 1000000.0);
768-
write_rate = (double) BLCKSZ * VacuumPageDirty / (1024 * 1024) /
774+
write_rate = (double) BLCKSZ * PageDirtyOp / (1024 * 1024) /
769775
(secs_dur + usecs_dur / 1000000.0);
770776
}
771777
appendStringInfo(&buf, _("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"),
772778
read_rate, write_rate);
773779
appendStringInfo(&buf,
774780
_("buffer usage: %lld hits, %lld misses, %lld dirtied\n"),
775-
(long long) VacuumPageHit,
776-
(long long) VacuumPageMiss,
777-
(long long) VacuumPageDirty);
781+
(long long) PageHitOp,
782+
(long long) PageMissOp,
783+
(long long) PageDirtyOp);
778784
appendStringInfo(&buf,
779785
_("WAL usage: %lld records, %lld full page images, %llu bytes\n"),
780786
(long long) walusage.wal_records,

0 commit comments

Comments
 (0)