From 6296e78c3d2c7406bb450c5ae477b2fef58f155e Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Tue, 13 Oct 2026 13:47:25 +0900 Subject: [PATCH] Add "own_hash" to pg_stat_kind_info This is a follow-up of 44539786b829, to reflect the value of the new "own_hash" option to pg_stat_kind_info. Thanks to this change, it becomes possible to know if a stats kind has the idea to use its own shared hashtable in pgstats. Bump catalog version. Author: Sami Imseih Reviewed-by: Michael Paquier Reviewed-by: Bertrand Drouvot Discussion: https://postgr.es/m/CAA5RZ0supQBxSkh=CWB39=j+cL3hHcLPki3tcBk0B1r4fesg_g@mail.gmail.com --- doc/src/sgml/monitoring.sgml | 13 +++++++++++++ src/backend/catalog/system_views.sql | 1 + src/backend/utils/activity/pgstat_kind.c | 7 ++++--- src/include/catalog/catversion.h | 2 +- src/include/catalog/pg_proc.dat | 7 ++++--- .../modules/test_custom_stats/t/001_custom_stats.pl | 10 +++++++--- src/test/regress/expected/rules.out | 3 ++- 7 files changed, 32 insertions(+), 11 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/catversion.h b/src/include/catalog/catversion.h index 9b6ef64a04e..a326c555328 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -57,6 +57,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 202610061 +#define CATALOG_VERSION_NO 202610131 #endif diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index f46427258e3..5e4c9e503f8 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -6075,9 +6075,10 @@ { 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 67e0c4e63d0..88dce8caffb 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 @@ -33,12 +33,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 = ( @@ -66,6 +66,10 @@ foreach my $stats_kind (@var_stats_kinds) "'$kind_name'"); $node->restart; + $result = $node->safe_psql('postgres', + "SELECT own_hash FROM pg_stat_kind_info WHERE name = '$kind_name'"); + is($result, $own_hash, "dedicated hash reported for $kind_name"); + # Create entries for variable-sized stats. $node->safe_psql('postgres', q(select test_custom_stats_var_create('entry1', 'Test entry 1'))); 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,