]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Change pgstat_report_vacuum() to use Relation
authorMichael Paquier <michael@paquier.xyz>
Wed, 17 Dec 2025 02:26:17 +0000 (11:26 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 17 Dec 2025 02:26:17 +0000 (11:26 +0900)
This change makes pgstat_report_vacuum() more consistent with
pgstat_report_analyze(), that also uses a Relation.  This enforces a
policy that callers of this routine should open and lock the relation
whose statistics are updated before calling this routine.  We will
unlikely have a lot of callers of this routine in the tree, but it seems
like a good idea to imply this requirement in the long run.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Suggested-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/aUEA6UZZkDCQFgSA@ip-10-97-1-34.eu-west-3.compute.internal

src/backend/access/heap/vacuumlazy.c
src/backend/utils/activity/pgstat_relation.c
src/include/pgstat.h

index 62035b7f9c3e86f7e1fe8d4f98d3d42995f0388b..30778a15639e790fcd99ccfba26b3c46a031b6fd 100644 (file)
@@ -961,8 +961,7 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
         * soon in cases where the failsafe prevented significant amounts of heap
         * vacuuming.
         */
-       pgstat_report_vacuum(RelationGetRelid(rel),
-                                                rel->rd_rel->relisshared,
+       pgstat_report_vacuum(rel,
                                                 Max(vacrel->new_live_tuples, 0),
                                                 vacrel->recently_dead_tuples +
                                                 vacrel->missed_dead_tuples,
index b90754f85788b8102c89be5cbe25a4ba49e56b35..55a10c299db178ac7fde6a86fafcf89a3ed013f0 100644 (file)
@@ -207,14 +207,13 @@ pgstat_drop_relation(Relation rel)
  * Report that the table was just vacuumed and flush IO statistics.
  */
 void
-pgstat_report_vacuum(Oid tableoid, bool shared,
-                                        PgStat_Counter livetuples, PgStat_Counter deadtuples,
-                                        TimestampTz starttime)
+pgstat_report_vacuum(Relation rel, PgStat_Counter livetuples,
+                                        PgStat_Counter deadtuples, TimestampTz starttime)
 {
        PgStat_EntryRef *entry_ref;
        PgStatShared_Relation *shtabentry;
        PgStat_StatTabEntry *tabentry;
-       Oid                     dboid = (shared ? InvalidOid : MyDatabaseId);
+       Oid                     dboid = (rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId);
        TimestampTz ts;
        PgStat_Counter elapsedtime;
 
@@ -226,8 +225,8 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
        elapsedtime = TimestampDifferenceMilliseconds(starttime, ts);
 
        /* block acquiring lock for the same reason as pgstat_report_autovac() */
-       entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_RELATION,
-                                                                                       dboid, tableoid, false);
+       entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_RELATION, dboid,
+                                                                                       RelationGetRelid(rel), false);
 
        shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
        tabentry = &shtabentry->stats;
index f23dd5870da7807ff28011943c2e3733e40d8369..6714363144a01531ed9f3fc209f43c7d81691eab 100644 (file)
@@ -669,8 +669,8 @@ extern void pgstat_init_relation(Relation rel);
 extern void pgstat_assoc_relation(Relation rel);
 extern void pgstat_unlink_relation(Relation rel);
 
-extern void pgstat_report_vacuum(Oid tableoid, bool shared,
-                                                                PgStat_Counter livetuples, PgStat_Counter deadtuples,
+extern void pgstat_report_vacuum(Relation rel, PgStat_Counter livetuples,
+                                                                PgStat_Counter deadtuples,
                                                                 TimestampTz starttime);
 extern void pgstat_report_analyze(Relation rel,
                                                                  PgStat_Counter livetuples, PgStat_Counter deadtuples,