From 6fde2d9a005a5bc04aa059d3faeb865c8dd322ce Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Mon, 21 Aug 2023 13:32:14 +0900 Subject: Fix pg_stat_reset_single_table_counters() for shared relations This commit fixes the function of $subject for shared relations. This feature has been added by e042678. Unfortunately, this new behavior got removed by 5891c7a when moving statistics to shared memory. Reported-by: Mitsuru Hinata Author: Masahiro Ikeda Reviewed-by: Kyotaro Horiguchi, Masahiko Sawada Discussion: https://postgr.es/m/7cc69f863d9b1bc677544e3accd0e4b4@oss.nttdata.com Backpatch-through: 15 --- src/backend/utils/adt/pgstatfuncs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (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 2a4c8ef87ff..2b9742ad21b 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -17,6 +17,7 @@ #include "access/htup_details.h" #include "access/xlog.h" #include "access/xlogprefetcher.h" +#include "catalog/catalog.h" #include "catalog/pg_authid.h" #include "catalog/pg_type.h" #include "common/ip.h" @@ -1776,13 +1777,17 @@ pg_stat_reset_shared(PG_FUNCTION_ARGS) PG_RETURN_VOID(); } -/* Reset a single counter in the current database */ +/* + * Reset a statistics for a single object, which may be of current + * database or shared across all databases in the cluster. + */ Datum pg_stat_reset_single_table_counters(PG_FUNCTION_ARGS) { Oid taboid = PG_GETARG_OID(0); + Oid dboid = (IsSharedRelation(taboid) ? InvalidOid : MyDatabaseId); - pgstat_reset(PGSTAT_KIND_RELATION, MyDatabaseId, taboid); + pgstat_reset(PGSTAT_KIND_RELATION, dboid, taboid); PG_RETURN_VOID(); } -- cgit v1.2.3