mirror of
https://github.com/postgres/postgres.git
synced 2025-12-18 05:01:01 +03:00
Change pgstat_report_vacuum() to use Relation
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
This commit is contained in:
@@ -961,8 +961,7 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
|
|||||||
* soon in cases where the failsafe prevented significant amounts of heap
|
* soon in cases where the failsafe prevented significant amounts of heap
|
||||||
* vacuuming.
|
* vacuuming.
|
||||||
*/
|
*/
|
||||||
pgstat_report_vacuum(RelationGetRelid(rel),
|
pgstat_report_vacuum(rel,
|
||||||
rel->rd_rel->relisshared,
|
|
||||||
Max(vacrel->new_live_tuples, 0),
|
Max(vacrel->new_live_tuples, 0),
|
||||||
vacrel->recently_dead_tuples +
|
vacrel->recently_dead_tuples +
|
||||||
vacrel->missed_dead_tuples,
|
vacrel->missed_dead_tuples,
|
||||||
|
|||||||
@@ -207,14 +207,13 @@ pgstat_drop_relation(Relation rel)
|
|||||||
* Report that the table was just vacuumed and flush IO statistics.
|
* Report that the table was just vacuumed and flush IO statistics.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
pgstat_report_vacuum(Oid tableoid, bool shared,
|
pgstat_report_vacuum(Relation rel, PgStat_Counter livetuples,
|
||||||
PgStat_Counter livetuples, PgStat_Counter deadtuples,
|
PgStat_Counter deadtuples, TimestampTz starttime)
|
||||||
TimestampTz starttime)
|
|
||||||
{
|
{
|
||||||
PgStat_EntryRef *entry_ref;
|
PgStat_EntryRef *entry_ref;
|
||||||
PgStatShared_Relation *shtabentry;
|
PgStatShared_Relation *shtabentry;
|
||||||
PgStat_StatTabEntry *tabentry;
|
PgStat_StatTabEntry *tabentry;
|
||||||
Oid dboid = (shared ? InvalidOid : MyDatabaseId);
|
Oid dboid = (rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId);
|
||||||
TimestampTz ts;
|
TimestampTz ts;
|
||||||
PgStat_Counter elapsedtime;
|
PgStat_Counter elapsedtime;
|
||||||
|
|
||||||
@@ -226,8 +225,8 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
|
|||||||
elapsedtime = TimestampDifferenceMilliseconds(starttime, ts);
|
elapsedtime = TimestampDifferenceMilliseconds(starttime, ts);
|
||||||
|
|
||||||
/* block acquiring lock for the same reason as pgstat_report_autovac() */
|
/* block acquiring lock for the same reason as pgstat_report_autovac() */
|
||||||
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_RELATION,
|
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_RELATION, dboid,
|
||||||
dboid, tableoid, false);
|
RelationGetRelid(rel), false);
|
||||||
|
|
||||||
shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
|
shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
|
||||||
tabentry = &shtabentry->stats;
|
tabentry = &shtabentry->stats;
|
||||||
|
|||||||
@@ -669,8 +669,8 @@ extern void pgstat_init_relation(Relation rel);
|
|||||||
extern void pgstat_assoc_relation(Relation rel);
|
extern void pgstat_assoc_relation(Relation rel);
|
||||||
extern void pgstat_unlink_relation(Relation rel);
|
extern void pgstat_unlink_relation(Relation rel);
|
||||||
|
|
||||||
extern void pgstat_report_vacuum(Oid tableoid, bool shared,
|
extern void pgstat_report_vacuum(Relation rel, PgStat_Counter livetuples,
|
||||||
PgStat_Counter livetuples, PgStat_Counter deadtuples,
|
PgStat_Counter deadtuples,
|
||||||
TimestampTz starttime);
|
TimestampTz starttime);
|
||||||
extern void pgstat_report_analyze(Relation rel,
|
extern void pgstat_report_analyze(Relation rel,
|
||||||
PgStat_Counter livetuples, PgStat_Counter deadtuples,
|
PgStat_Counter livetuples, PgStat_Counter deadtuples,
|
||||||
|
|||||||
Reference in New Issue
Block a user