From b71bae41a0cdda879db39d9946d2cc4af910bed1 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 8 Oct 2025 12:43:40 +0900 Subject: Add stats_reset to pg_stat_user_functions It is possible to call pg_stat_reset_single_function_counters() for a single function, but the reset time was missing the system view showing its statistics. Like all the fields of pg_stat_user_functions, the GUC track_functions needs to be enabled to show the statistics about function executions. Bump catalog version. Bump PGSTAT_FILE_FORMAT_ID, as a result of the new field added to PgStat_StatFuncEntry. Author: Bertrand Drouvot Discussion: https://postgr.es/m/aONjnsaJSx-nEdfU@paquier.xyz --- src/backend/utils/adt/pgstatfuncs.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/backend/utils/adt/pgstatfuncs.c') diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 7e89a8048d5..3802a4cb888 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -203,6 +203,24 @@ PG_STAT_GET_FUNCENTRY_FLOAT8_MS(total_time) /* pg_stat_get_function_self_time */ PG_STAT_GET_FUNCENTRY_FLOAT8_MS(self_time) +Datum +pg_stat_get_function_stat_reset_time(PG_FUNCTION_ARGS) +{ + Oid funcid = PG_GETARG_OID(0); + TimestampTz result; + PgStat_StatFuncEntry *funcentry; + + if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL) + result = 0; + else + result = funcentry->stat_reset_timestamp; + + if (result == 0) + PG_RETURN_NULL(); + else + PG_RETURN_TIMESTAMPTZ(result); +} + Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS) { -- cgit v1.2.3