diff options
author | Masahiko Sawada <msawada@postgresql.org> | 2024-08-13 18:49:45 -0700 |
---|---|---|
committer | Masahiko Sawada <msawada@postgresql.org> | 2024-08-13 18:49:45 -0700 |
commit | c584781bcc686ebc0b3139e3e166607537336f69 (patch) | |
tree | 6394b70a67de08a11ed515cdda2ce75d6c6cbbfa /src/backend/access/heap/vacuumlazy.c | |
parent | 2488058dc356a43455b21a099ea879fff9266634 (diff) |
Use pgBufferUsage for buffer usage tracking in analyze.
Previously, (auto)analyze used global variables VacuumPageHit,
VacuumPageMiss, and VacuumPageDirty to track buffer usage. However,
pgBufferUsage provides a more generic way to track buffer usage with
support functions.
This change replaces those global variables with pgBufferUsage in
analyze. Since analyze was the sole user of those variables, it
removes their declarations. Vacuum previously used those variables but
replaced them with pgBufferUsage as part of a bug fix, commit
5cd72cc0c.
Additionally, it adjusts the buffer usage message in both vacuum and
analyze for better consistency.
Author: Anthonin Bonnefoy
Reviewed-by: Masahiko Sawada, Michael Paquier
Discussion: https://postgr.es/m/CAO6_Xqr__kTTCLkftqS0qSCm-J7_xbRG3Ge2rWhucxQJMJhcRA%40mail.gmail.com
Diffstat (limited to 'src/backend/access/heap/vacuumlazy.c')
-rw-r--r-- | src/backend/access/heap/vacuumlazy.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 835b53415d0..d82aa3d4896 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -608,6 +608,9 @@ heap_vacuum_rel(Relation rel, VacuumParams *params, int32 diff; double read_rate = 0, write_rate = 0; + int64 total_blks_hit; + int64 total_blks_read; + int64 total_blks_dirtied; TimestampDifference(starttime, endtime, &secs_dur, &usecs_dur); memset(&walusage, 0, sizeof(WalUsage)); @@ -615,6 +618,13 @@ heap_vacuum_rel(Relation rel, VacuumParams *params, memset(&bufferusage, 0, sizeof(BufferUsage)); BufferUsageAccumDiff(&bufferusage, &pgBufferUsage, &startbufferusage); + total_blks_hit = bufferusage.shared_blks_hit + + bufferusage.local_blks_hit; + total_blks_read = bufferusage.shared_blks_read + + bufferusage.local_blks_read; + total_blks_dirtied = bufferusage.shared_blks_dirtied + + bufferusage.local_blks_dirtied; + initStringInfo(&buf); if (verbose) { @@ -740,18 +750,18 @@ heap_vacuum_rel(Relation rel, VacuumParams *params, } if (secs_dur > 0 || usecs_dur > 0) { - read_rate = (double) BLCKSZ * (bufferusage.shared_blks_read + bufferusage.local_blks_read) / + read_rate = (double) BLCKSZ * total_blks_read / (1024 * 1024) / (secs_dur + usecs_dur / 1000000.0); - write_rate = (double) BLCKSZ * (bufferusage.shared_blks_dirtied + bufferusage.local_blks_dirtied) / + write_rate = (double) BLCKSZ * total_blks_dirtied / (1024 * 1024) / (secs_dur + usecs_dur / 1000000.0); } appendStringInfo(&buf, _("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"), read_rate, write_rate); appendStringInfo(&buf, - _("buffer usage: %lld hits, %lld misses, %lld dirtied\n"), - (long long) (bufferusage.shared_blks_hit + bufferusage.local_blks_hit), - (long long) (bufferusage.shared_blks_read + bufferusage.local_blks_read), - (long long) (bufferusage.shared_blks_dirtied + bufferusage.local_blks_dirtied)); + _("buffer usage: %lld hits, %lld reads, %lld dirtied\n"), + (long long) total_blks_hit, + (long long) total_blks_read, + (long long) total_blks_dirtied); appendStringInfo(&buf, _("WAL usage: %lld records, %lld full page images, %llu bytes\n"), (long long) walusage.wal_records, |