From b30ae531911ee048139cdfceee721910d18573da Mon Sep 17 00:00:00 2001 From: Sami Imseih Date: Wed, 7 Oct 2026 18:03:00 +0000 Subject: [PATCH v6 2/2] pgstat: expose own_hash in pg_stat_kind_info Add an own_hash column to pg_stat_kind_info so callers can tell whether a variable-numbered stats kind stores entries in the shared pgstats hash or in its own dedicated hash. Updated Documentation and tests. Requires a catversion bump. Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/anX2J5yYsO9ae2Tq@bdtpg --- doc/src/sgml/monitoring.sgml | 13 +++++++++++++ src/backend/catalog/system_views.sql | 1 + src/backend/utils/activity/pgstat_kind.c | 7 ++++--- src/include/catalog/pg_proc.dat | 6 +++--- .../modules/test_custom_stats/t/001_custom_stats.pl | 6 +++--- src/test/regress/expected/rules.out | 3 ++- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 6337d2a3d25..67ae6fd5f7e 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -3574,6 +3574,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage + + + + own_hash boolean + + + For variable-numbered statistics kinds, true if entries of this kind + are stored in a dedicated hash table, false if they are stored in the + shared hash table. False for fixed-numbered statistics kinds. + + + + diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 809b9c0f1e4..ddf801307eb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1290,6 +1290,7 @@ CREATE VIEW pg_stat_kind_info AS k.fixed_amount, k.accessed_across_databases, k.write_to_file, + k.own_hash, k.entry_count FROM pg_stat_get_kind_info() k; diff --git a/src/backend/utils/activity/pgstat_kind.c b/src/backend/utils/activity/pgstat_kind.c index 6c53b7e49bf..d0319825fe1 100644 --- a/src/backend/utils/activity/pgstat_kind.c +++ b/src/backend/utils/activity/pgstat_kind.c @@ -31,7 +31,7 @@ Datum pg_stat_get_kind_info(PG_FUNCTION_ARGS) { -#define PG_STAT_KIND_INFO_COLS 7 +#define PG_STAT_KIND_INFO_COLS 8 ReturnSetInfo *rsinfo; InitMaterializedSRF(fcinfo, 0); @@ -54,15 +54,16 @@ pg_stat_get_kind_info(PG_FUNCTION_ARGS) values[3] = BoolGetDatum(info->fixed_amount); values[4] = BoolGetDatum(info->accessed_across_databases); values[5] = BoolGetDatum(info->write_to_file); + values[6] = BoolGetDatum(info->own_hash); /* * When track_entry_count is disabled, use NULL. Fixed-sized stats * kinds report NULL here. */ if (info->track_entry_count) - values[6] = Int64GetDatum(pgstat_get_entry_count(kind)); + values[7] = Int64GetDatum(pgstat_get_entry_count(kind)); else - nulls[6] = true; + nulls[7] = true; tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls); } diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index f46427258e3..a9bb4fc5ebe 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -6075,9 +6075,9 @@ { oid => '8683', descr => 'statistics: information about statistics kinds', proname => 'pg_stat_get_kind_info', prorows => '20', proretset => 't', provolatile => 'v', proparallel => 'r', prorettype => 'record', - proargtypes => '', proallargtypes => '{int4,text,bool,bool,bool,bool,int8}', - proargmodes => '{o,o,o,o,o,o,o}', - proargnames => '{id,name,builtin,fixed_amount,accessed_across_databases,write_to_file,entry_count}', + proargtypes => '', proallargtypes => '{int4,text,bool,bool,bool,bool,bool,int8}', + proargmodes => '{o,o,o,o,o,o,o,o}', + proargnames => '{id,name,builtin,fixed_amount,accessed_across_databases,write_to_file,own_hash,entry_count}', prosrc => 'pg_stat_get_kind_info' }, { oid => '1136', descr => 'statistics: information about WAL activity', diff --git a/src/test/modules/test_custom_stats/t/001_custom_stats.pl b/src/test/modules/test_custom_stats/t/001_custom_stats.pl index 85366fb088d..6f6f27cfe7d 100644 --- a/src/test/modules/test_custom_stats/t/001_custom_stats.pl +++ b/src/test/modules/test_custom_stats/t/001_custom_stats.pl @@ -35,12 +35,12 @@ $node->safe_psql('postgres', q(CREATE EXTENSION test_custom_fixed_stats)); $result = $node->safe_psql( 'postgres', q(SELECT id, name, builtin, fixed_amount, accessed_across_databases, - write_to_file + write_to_file, own_hash FROM pg_stat_kind_info WHERE name LIKE 'test_custom%' ORDER BY id)); is( $result, - qq{25|test_custom_var_stats|f|f|t|t -26|test_custom_fixed_stats|f|t|f|t}, + qq{25|test_custom_var_stats|f|f|t|t|f +26|test_custom_fixed_stats|f|t|f|t|f}, "custom stats kinds visible in pg_stat_kind_info"); my @var_stats_kinds = ( diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 0addd043e68..4addeba2508 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1973,8 +1973,9 @@ pg_stat_kind_info| SELECT id, fixed_amount, accessed_across_databases, write_to_file, + own_hash, entry_count - FROM pg_stat_get_kind_info() k(id, name, builtin, fixed_amount, accessed_across_databases, write_to_file, entry_count); + FROM pg_stat_get_kind_info() k(id, name, builtin, fixed_amount, accessed_across_databases, write_to_file, own_hash, entry_count); pg_stat_lock| SELECT locktype, waits, wait_time, -- 2.50.1