mirror of
https://github.com/postgres/postgres.git
synced 2025-12-22 17:42:17 +03:00
Count updates that move row to a new page.
Add pgstat counter to track row updates that result in the successor version going to a new heap page, leaving behind an original version whose t_ctid points to the new version. The current count is shown by the n_tup_newpage_upd column of each of the pg_stat_*_tables views. The new n_tup_newpage_upd column complements the existing n_tup_hot_upd and n_tup_upd columns. Tables that have high n_tup_newpage_upd values (relative to n_tup_upd) are good candidates for tuning heap fillfactor. Corey Huinker, with small tweaks by me. Author: Corey Huinker <corey.huinker@gmail.com> Reviewed-By: Peter Geoghegan <pg@bowt.ie> Reviewed-By: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CADkLM=ded21M9iZ36hHm-vj2rE2d=zcKpUQMds__Xm2pxLfHKA@mail.gmail.com
This commit is contained in:
@@ -373,8 +373,10 @@ pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
|
||||
* count a tuple update
|
||||
*/
|
||||
void
|
||||
pgstat_count_heap_update(Relation rel, bool hot)
|
||||
pgstat_count_heap_update(Relation rel, bool hot, bool newpage)
|
||||
{
|
||||
Assert(!(hot && newpage));
|
||||
|
||||
if (pgstat_should_count_relation(rel))
|
||||
{
|
||||
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
|
||||
@@ -382,9 +384,14 @@ pgstat_count_heap_update(Relation rel, bool hot)
|
||||
ensure_tabstat_xact_level(pgstat_info);
|
||||
pgstat_info->trans->tuples_updated++;
|
||||
|
||||
/* t_tuples_hot_updated is nontransactional, so just advance it */
|
||||
/*
|
||||
* t_tuples_hot_updated and t_tuples_newpage_updated counters are
|
||||
* nontransactional, so just advance them
|
||||
*/
|
||||
if (hot)
|
||||
pgstat_info->t_counts.t_tuples_hot_updated++;
|
||||
else if (newpage)
|
||||
pgstat_info->t_counts.t_tuples_newpage_updated++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -804,6 +811,7 @@ pgstat_relation_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
|
||||
tabentry->tuples_updated += lstats->t_counts.t_tuples_updated;
|
||||
tabentry->tuples_deleted += lstats->t_counts.t_tuples_deleted;
|
||||
tabentry->tuples_hot_updated += lstats->t_counts.t_tuples_hot_updated;
|
||||
tabentry->tuples_newpage_updated += lstats->t_counts.t_tuples_newpage_updated;
|
||||
|
||||
/*
|
||||
* If table was truncated/dropped, first reset the live/dead counters.
|
||||
|
||||
@@ -92,6 +92,9 @@ PG_STAT_GET_RELENTRY_INT64(tuples_fetched)
|
||||
/* pg_stat_get_tuples_hot_updated */
|
||||
PG_STAT_GET_RELENTRY_INT64(tuples_hot_updated)
|
||||
|
||||
/* pg_stat_get_tuples_newpage_updated */
|
||||
PG_STAT_GET_RELENTRY_INT64(tuples_newpage_updated)
|
||||
|
||||
/* pg_stat_get_tuples_inserted */
|
||||
PG_STAT_GET_RELENTRY_INT64(tuples_inserted)
|
||||
|
||||
@@ -1618,6 +1621,21 @@ pg_stat_get_xact_tuples_hot_updated(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_INT64(result);
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_stat_get_xact_tuples_newpage_updated(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid relid = PG_GETARG_OID(0);
|
||||
int64 result;
|
||||
PgStat_TableStatus *tabentry;
|
||||
|
||||
if ((tabentry = find_tabstat_entry(relid)) == NULL)
|
||||
result = 0;
|
||||
else
|
||||
result = (int64) (tabentry->t_counts.t_tuples_newpage_updated);
|
||||
|
||||
PG_RETURN_INT64(result);
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_stat_get_xact_blocks_fetched(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user