diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 937d6ce1b57..12b9ee20d4a 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -509,6 +509,16 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
+
+ pg_stat_kind_infopg_stat_kind_info
+
+ One row for each registered statistics kind, showing information
+ about each kind.
+ See
+ pg_stat_kind_info for details.
+
+
+
pg_stat_lockpg_stat_lock
@@ -3303,6 +3313,124 @@ description | Waiting for a newly initialized WAL file to reach durable storage
+
+ pg_stat_kind_info
+
+
+ pg_stat_kind_info
+
+
+
+ The pg_stat_kind_info view contains one row for
+ each registered statistics kind, including both built-in and custom kinds.
+
+
+
+ pg_stat_kind_info View
+
+
+
+
+
+ Column Type
+
+
+ Description
+
+
+
+
+
+
+
+
+ idinteger
+
+
+ Numeric identifier of the statistics kind.
+
+
+
+
+
+
+
+ nametext
+
+
+ Name of the statistics kind.
+
+
+
+
+
+
+
+ builtinboolean
+
+
+ True if this is a built-in statistics kind, false if it was registered
+ by an extension.
+
+
+
+
+
+
+
+ fixed_amountboolean
+
+
+ True if this kind tracks a fixed amount of data (a single, statically
+ allocated entry), false if it tracks a variable number of entries
+ keyed by object identifier.
+
+
+
+
+
+
+
+ accessed_across_databasesboolean
+
+
+ True if entries of this kind are accessed across databases (cluster-wide
+ statistics), false if they are scoped to a single database.
+
+
+
+
+
+
+
+ write_to_fileboolean
+
+
+ True if entries of this kind are persisted to the statistics file at
+ shutdown and reloaded on startup, false if they are kept only in
+ shared memory.
+
+
+
+
+
+
+
+ entry_countbigint
+
+
+ Number of tracked entries for this kind. For variable-numbered kinds,
+ this is the number of objects currently tracked.
+ NULL for fixed-sized statistics kinds, or if the
+ kind does not track entry counts.
+
+
+
+
+
+
+
+
pg_stat_lock
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 8f129baec90..d10b50f0097 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1282,6 +1282,17 @@ SELECT
b.stats_reset
FROM pg_stat_get_io() b;
+CREATE VIEW pg_stat_kind_info AS
+ SELECT
+ k.id,
+ k.name,
+ k.builtin,
+ k.fixed_amount,
+ k.accessed_across_databases,
+ k.write_to_file,
+ k.entry_count
+ FROM pg_stat_get_kind_info() k;
+
CREATE VIEW pg_stat_wal AS
SELECT
w.wal_records,
diff --git a/src/backend/utils/activity/Makefile b/src/backend/utils/activity/Makefile
index ca3ef89bf59..5fed953c28a 100644
--- a/src/backend/utils/activity/Makefile
+++ b/src/backend/utils/activity/Makefile
@@ -26,6 +26,7 @@ OBJS = \
pgstat_database.o \
pgstat_function.o \
pgstat_io.o \
+ pgstat_kind.o \
pgstat_lock.o \
pgstat_relation.o \
pgstat_replslot.o \
diff --git a/src/backend/utils/activity/meson.build b/src/backend/utils/activity/meson.build
index 1aa7ece5290..470b5dac402 100644
--- a/src/backend/utils/activity/meson.build
+++ b/src/backend/utils/activity/meson.build
@@ -11,6 +11,7 @@ backend_sources += files(
'pgstat_database.c',
'pgstat_function.c',
'pgstat_io.c',
+ 'pgstat_kind.c',
'pgstat_lock.c',
'pgstat_relation.c',
'pgstat_replslot.c',
diff --git a/src/backend/utils/activity/pgstat_kind.c b/src/backend/utils/activity/pgstat_kind.c
new file mode 100644
index 00000000000..6c53b7e49bf
--- /dev/null
+++ b/src/backend/utils/activity/pgstat_kind.c
@@ -0,0 +1,72 @@
+/*-------------------------------------------------------------------------
+ *
+ * pgstat_kind.c
+ * Functions related to statistics kinds.
+ *
+ * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ * src/backend/utils/activity/pgstat_kind.c
+ *
+ *-------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include "fmgr.h"
+#include "funcapi.h"
+#include "utils/builtins.h"
+#include "utils/fmgrprotos.h"
+#include "utils/pgstat_internal.h"
+#include "utils/pgstat_kind.h"
+#include "utils/tuplestore.h"
+
+
+/*
+ * pg_stat_get_kind_info
+ *
+ * Get information about the statistics kinds registered into the system.
+ */
+Datum
+pg_stat_get_kind_info(PG_FUNCTION_ARGS)
+{
+#define PG_STAT_KIND_INFO_COLS 7
+ ReturnSetInfo *rsinfo;
+
+ InitMaterializedSRF(fcinfo, 0);
+ rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
+
+ for (int kind = PGSTAT_KIND_MIN; kind <= PGSTAT_KIND_MAX; kind++)
+ {
+ Datum values[PG_STAT_KIND_INFO_COLS] = {0};
+ bool nulls[PG_STAT_KIND_INFO_COLS] = {0};
+ const PgStat_KindInfo *info;
+
+ info = pgstat_get_kind_info(kind);
+ if (info == NULL)
+ continue;
+
+ values[0] = Int32GetDatum(kind);
+ values[1] = CStringGetTextDatum(info->name);
+
+ values[2] = BoolGetDatum(pgstat_is_kind_builtin(kind));
+ values[3] = BoolGetDatum(info->fixed_amount);
+ values[4] = BoolGetDatum(info->accessed_across_databases);
+ values[5] = BoolGetDatum(info->write_to_file);
+
+ /*
+ * 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));
+ else
+ nulls[6] = true;
+
+ tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
+ }
+
+ return (Datum) 0;
+#undef PG_STAT_KIND_INFO_COLS
+}
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index 227d85762a1..fa8507761ae 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -57,6 +57,6 @@
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 202607011
+#define CATALOG_VERSION_NO 202607021
#endif
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 9e24b2f6299..3cb84359adf 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -6078,6 +6078,14 @@
proargnames => '{backend_pid,backend_type,object,context,reads,read_bytes,read_time,writes,write_bytes,write_time,writebacks,writeback_time,extends,extend_bytes,extend_time,hits,evictions,reuses,fsyncs,fsync_time,stats_reset}',
prosrc => 'pg_stat_get_backend_io' },
+{ 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}',
+ prosrc => 'pg_stat_get_kind_info' },
+
{ oid => '1136', descr => 'statistics: information about WAL activity',
proname => 'pg_stat_get_wal', proisstrict => 'f', provolatile => 's',
proparallel => 'r', prorettype => 'record', proargtypes => '',
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 9e6a7a38577..69f2284229e 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
@@ -27,6 +27,18 @@ $node->start;
$node->safe_psql('postgres', q(CREATE EXTENSION test_custom_var_stats));
$node->safe_psql('postgres', q(CREATE EXTENSION test_custom_fixed_stats));
+# Verify custom stats kinds appear in pg_stat_kind_info.
+my $result = $node->safe_psql(
+ 'postgres',
+ q(SELECT id, name, builtin, fixed_amount, accessed_across_databases,
+ write_to_file
+ 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},
+ "custom stats kinds visible in pg_stat_kind_info");
+
# Create entries for variable-sized stats.
$node->safe_psql('postgres',
q(select test_custom_stats_var_create('entry1', 'Test entry 1')));
@@ -63,7 +75,7 @@ $node->safe_psql('postgres', q(select test_custom_stats_fixed_update()));
$node->safe_psql('postgres', q(select test_custom_stats_fixed_update()));
# Test data reports.
-my $result = $node->safe_psql('postgres',
+$result = $node->safe_psql('postgres',
q(select * from test_custom_stats_var_report('entry1')));
is( $result,
"entry1|2|Test entry 1",
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index a65a5bf0c4f..e266f501d87 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -1967,6 +1967,14 @@ pg_stat_io| SELECT backend_type,
fsync_time,
stats_reset
FROM pg_stat_get_io() b(backend_type, object, context, reads, read_bytes, read_time, writes, write_bytes, write_time, writebacks, writeback_time, extends, extend_bytes, extend_time, hits, evictions, reuses, fsyncs, fsync_time, stats_reset);
+pg_stat_kind_info| SELECT 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, entry_count);
pg_stat_lock| SELECT locktype,
waits,
wait_time,
diff --git a/src/test/regress/expected/stats.out b/src/test/regress/expected/stats.out
index fa550676f83..03cbc1cdef5 100644
--- a/src/test/regress/expected/stats.out
+++ b/src/test/regress/expected/stats.out
@@ -113,6 +113,29 @@ walwriter|wal|init
walwriter|wal|normal
(95 rows)
\a
+-- List of registered statistics kinds.
+SELECT id, name, fixed_amount,
+ accessed_across_databases AS across_db, write_to_file
+ FROM pg_stat_kind_info
+ WHERE builtin
+ ORDER BY id;
+ id | name | fixed_amount | across_db | write_to_file
+----+--------------+--------------+-----------+---------------
+ 1 | database | f | t | t
+ 2 | relation | f | f | t
+ 3 | function | f | f | t
+ 4 | replslot | f | t | t
+ 5 | subscription | f | t | t
+ 6 | backend | f | t | f
+ 7 | archiver | t | f | t
+ 8 | bgwriter | t | f | t
+ 9 | checkpointer | t | f | t
+ 10 | io | t | f | t
+ 11 | lock | t | f | t
+ 12 | slru | t | f | t
+ 13 | wal | t | f | t
+(13 rows)
+
-- ensure that both seqscan and indexscan plans are allowed
SET enable_seqscan TO on;
SET enable_indexscan TO on;
diff --git a/src/test/regress/sql/stats.sql b/src/test/regress/sql/stats.sql
index f5683302a75..4c265d1245c 100644
--- a/src/test/regress/sql/stats.sql
+++ b/src/test/regress/sql/stats.sql
@@ -14,6 +14,13 @@ SELECT backend_type, object, context FROM pg_stat_io
ORDER BY backend_type COLLATE "C", object COLLATE "C", context COLLATE "C";
\a
+-- List of registered statistics kinds.
+SELECT id, name, fixed_amount,
+ accessed_across_databases AS across_db, write_to_file
+ FROM pg_stat_kind_info
+ WHERE builtin
+ ORDER BY id;
+
-- ensure that both seqscan and indexscan plans are allowed
SET enable_seqscan TO on;
SET enable_indexscan TO on;