diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index caa7523484..85e9b26040 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -228,15 +228,11 @@ typedef struct LVSavedErrInfo } LVSavedErrInfo; /* - * Cut-off values of parameters which changes implicitly during a vacuum - * process. - * Vacuum can't control their values, so we should store them before and after - * the processing. + * Counters and usage data for extended stats tracking. */ typedef struct LVExtStatCounters { - TimestampTz time; - PGRUsage ru; + TimestampTz starttime; WalUsage walusage; BufferUsage bufusage; double VacuumDelayTime; @@ -296,26 +292,21 @@ static void update_vacuum_error_info(LVRelState *vacrel, static void restore_vacuum_error_info(LVRelState *vacrel, const LVSavedErrInfo *saved_vacrel); -/* ---------- +/* * extvac_stats_start() - * - * Save cut-off values of extended vacuum counters before start of a relation - * processing. - * ---------- + * Save extended stats counters before start of relation processing. */ static void extvac_stats_start(Relation rel, LVExtStatCounters *counters) { TimestampTz starttime; - PGRUsage ru0; memset(counters, 0, sizeof(LVExtStatCounters)); - pg_rusage_init(&ru0); starttime = GetCurrentTimestamp(); - counters->ru = ru0; - counters->time = starttime; + counters->starttime = starttime; counters->walusage = pgWalUsage; counters->bufusage = pgBufferUsage; counters->VacuumDelayTime = VacuumDelayTime; @@ -324,7 +315,7 @@ extvac_stats_start(Relation rel, LVExtStatCounters *counters) if (!rel->pgstat_info || !pgstat_track_counts) /* - * if something goes wrong or an user doesn't want to track a database + * if something goes wrong or user doesn't want to track a database * activity - just suppress it. */ return; @@ -333,11 +324,10 @@ extvac_stats_start(Relation rel, LVExtStatCounters *counters) counters->blocks_hit = rel->pgstat_info->counts.blocks_hit; } -/* ---------- +/* * extvac_stats_end() - * - * Called to finish an extended vacuum statistic gathering and form a report. - * ---------- + * Called to finish an extended vacuum statistic gathering and form a report. */ static void extvac_stats_end(Relation rel, LVExtStatCounters *counters, @@ -357,7 +347,7 @@ extvac_stats_end(Relation rel, LVExtStatCounters *counters, BufferUsageAccumDiff(&bufusage, &pgBufferUsage, &counters->bufusage); endtime = GetCurrentTimestamp(); - TimestampDifference(counters->time, endtime, &secs, &usecs); + TimestampDifference(counters->starttime, endtime, &secs, &usecs); memset(report, 0, sizeof(ExtVacReport)); @@ -703,7 +693,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params, extVacReport.pages_all_visible = vacrel->set_all_visible_pages; extVacReport.tuples_deleted = vacrel->tuples_deleted; extVacReport.tuples_frozen = vacrel->tuples_frozen; - extVacReport.dead_tuples = vacrel->recently_dead_tuples + vacrel->missed_dead_tuples; + extVacReport.recently_dead_tuples = vacrel->recently_dead_tuples; extVacReport.index_vacuum_count = vacrel->num_index_scans; /* diff --git a/src/backend/access/heap/visibilitymap.c b/src/backend/access/heap/visibilitymap.c index d72cade60a..d25c9a3679 100644 --- a/src/backend/access/heap/visibilitymap.c +++ b/src/backend/access/heap/visibilitymap.c @@ -162,12 +162,9 @@ visibilitymap_clear(Relation rel, BlockNumber heapBlk, Buffer vmbuf, uint8 flags if (map[mapByte] & mask) { /* - * Initially, it didn't matter what type of flags (all-visible or frozen) we received, - * we just performed a reverse concatenation operation. But this information is very important - * for vacuum statistics. We need to find out this usingthe bit concatenation operation - * with the VISIBILITYMAP_ALL_VISIBLE and VISIBILITYMAP_ALL_FROZEN masks, - * and where the desired one matches, we increment the value there. - */ + * As part of vacuum stats, track how often all-visible or all-frozen + * bits are cleared. + */ if (map[mapByte] >> mapOffset & flags & VISIBILITYMAP_ALL_VISIBLE) pgstat_count_vm_rev_all_visible(rel); if (map[mapByte] >> mapOffset & flags & VISIBILITYMAP_ALL_FROZEN) diff --git a/src/backend/utils/activity/pgstat_relation.c b/src/backend/utils/activity/pgstat_relation.c index 2a2650ef2c..5dd8275671 100644 --- a/src/backend/utils/activity/pgstat_relation.c +++ b/src/backend/utils/activity/pgstat_relation.c @@ -205,11 +205,8 @@ pgstat_drop_relation(Relation rel) } } -/* --------- - * pgstat_report_vacuum_error() - - * - * Tell the collector about an (auto)vacuum interruption. - * --------- +/* + * Report an error while vacuuming. */ void pgstat_report_vacuum_error(Oid tableoid) @@ -228,7 +225,7 @@ pgstat_report_vacuum_error(Oid tableoid) shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats; tabentry = &shtabentry->stats; - tabentry->vacuum_ext.interrupts++; + tabentry->vacuum_ext.errors++; pgstat_unlock_entry(entry_ref); } @@ -1045,6 +1042,6 @@ pgstat_accumulate_extvac_stats(ExtVacReport *dst, ExtVacReport *src, dst->pages_all_visible += src->pages_all_visible; dst->tuples_deleted += src->tuples_deleted; dst->tuples_frozen += src->tuples_frozen; - dst->dead_tuples += src->dead_tuples; + dst->recently_dead_tuples += src->recently_dead_tuples; dst->index_vacuum_count += src->index_vacuum_count; -} \ No newline at end of file +} diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index e139ae5134..ab3fba3314 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -2217,7 +2217,7 @@ pg_stat_get_vacuum_tables(PG_FUNCTION_ARGS) values[i++] = Int64GetDatum(extvacuum->pages_all_visible); values[i++] = Int64GetDatum(extvacuum->tuples_deleted); values[i++] = Int64GetDatum(extvacuum->tuples_frozen); - values[i++] = Int64GetDatum(extvacuum->dead_tuples); + values[i++] = Int64GetDatum(extvacuum->recently_dead_tuples); values[i++] = Int64GetDatum(extvacuum->index_vacuum_count); values[i++] = Int64GetDatum(extvacuum->wal_records); @@ -2239,4 +2239,4 @@ pg_stat_get_vacuum_tables(PG_FUNCTION_ARGS) /* Returns the record as Datum */ PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls))); -} \ No newline at end of file +} diff --git a/src/include/pgstat.h b/src/include/pgstat.h index 5d1a3c536d..a6f363ac0d 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -169,25 +169,22 @@ typedef struct PgStat_BackendSubEntry PgStat_Counter conflict_count[CONFLICT_NUM_TYPES]; } PgStat_BackendSubEntry; -/* ---------- - * +/* * ExtVacReport * - * Additional statistics of vacuum processing over a heap relation. - * pages_removed is the amount by which the physically shrank, - * if any (ie the change in its total size on disk) - * pages_deleted refer to free space within the index file - * ---------- + * Additional statistics of vacuum processing over a single heap relation. */ typedef struct ExtVacReport { - int64 total_blks_read; /* number of pages that were missed in shared buffers during a vacuum of specific relation */ - int64 total_blks_hit; /* number of pages that were found in shared buffers during a vacuum of specific relation */ - int64 total_blks_dirtied; /* number of pages marked as 'Dirty' during a vacuum of specific relation. */ - int64 total_blks_written; /* number of pages written during a vacuum of specific relation. */ + /* number of blocks missed, hit, dirtied and written */ + int64 total_blks_read; + int64 total_blks_hit; + int64 total_blks_dirtied; + int64 total_blks_written; - int64 blks_fetched; /* number of a relation blocks, fetched during the vacuum. */ - int64 blks_hit; /* number of a relation blocks, found in shared buffers during the vacuum. */ + /* blocks missed and hit for just the heap */ + int64 blks_fetched; + int64 blks_hit; /* Vacuum WAL usage stats */ int64 wal_records; /* wal usage: number of WAL records */ @@ -203,13 +200,13 @@ typedef struct ExtVacReport /* Interruptions on any errors. */ int32 errors; - int64 pages_scanned; /* number of pages we examined */ - int64 pages_removed; /* number of pages removed by vacuum */ - int64 pages_frozen; /* number of pages marked in VM as frozen */ - int64 pages_all_visible; /* number of pages marked in VM as all-visible */ + int64 pages_scanned; /* heap pages examined (not skipped by VM) */ + int64 pages_removed; /* heap pages removed by vacuum "truncation" */ + int64 pages_frozen; /* pages marked in VM as frozen */ + int64 pages_all_visible; /* pages marked in VM as all-visible */ int64 tuples_deleted; /* tuples deleted by vacuum */ int64 tuples_frozen; /* tuples frozen up by vacuum */ - int64 dead_tuples; /* number of deleted tuples which vacuum cannot clean up by vacuum operation */ + int64 recently_dead_tuples; /* deleted tuples that are still visible to some transaction */ int64 index_vacuum_count; /* number of index vacuumings */ } ExtVacReport; @@ -442,10 +439,9 @@ typedef struct PgStat_StatDBEntry PgStat_Counter sessions_killed; PgStat_Counter parallel_workers_to_launch; PgStat_Counter parallel_workers_launched; + ExtVacReport vacuum_ext; /* extended vacuum statistics */ TimestampTz stat_reset_timestamp; - - ExtVacReport vacuum_ext; /* extended vacuum statistics */ } PgStat_StatDBEntry; typedef struct PgStat_StatFuncEntry