Enhance pg_stat_reset_single_table_counters function.
authorFujii Masao <fujii@postgresql.org>
Thu, 2 Sep 2021 05:01:06 +0000 (14:01 +0900)
committerFujii Masao <fujii@postgresql.org>
Thu, 2 Sep 2021 05:01:06 +0000 (14:01 +0900)
This commit allows pg_stat_reset_single_table_counters() to reset statistics
for a single relation shared across all databases in the cluster to zero.

Bump catalog version.

Author: B Sadhu Prasad Patro
Reviewed-by: Mahendra Singh Thalor, Himanshu Upadhyaya, Dilip Kumar, Fujii Masao
Discussion: https://postgr.es/m/CAFF0-CGy7EHeF=AqqkGMF85cySPQBgDcvNk73G2O0vL94O5U5A@mail.gmail.com

doc/src/sgml/monitoring.sgml
src/backend/postmaster/pgstat.c
src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat

index 74a58a916c15ae8fe64e69e0e20cbc8c442c8288..2281ba120f333745e96fb35a7f3e5e3f8729d108 100644 (file)
@@ -5097,7 +5097,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
        </para>
        <para>
         Resets statistics for a single table or index in the current database
-        to zero.
+        or shared across all databases in the cluster to zero.
        </para>
        <para>
         This function is restricted to superusers by default, but other users
index 4a280897b1907af2d08367fae3f693697efe4667..3450a10129bbf0e7bedcb19be3d0383ff5cc38a5 100644 (file)
@@ -38,6 +38,7 @@
 #include "access/transam.h"
 #include "access/twophase_rmgr.h"
 #include "access/xact.h"
+#include "catalog/catalog.h"
 #include "catalog/pg_database.h"
 #include "catalog/pg_proc.h"
 #include "common/ip.h"
@@ -5140,7 +5141,8 @@ pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len)
 /* ----------
  * pgstat_recv_resetsinglecounter() -
  *
- * Reset a statistics for a single object
+ * Reset a statistics for a single object, which may be of current
+ * database or shared across all databases in the cluster.
  * ----------
  */
 static void
@@ -5148,7 +5150,10 @@ pgstat_recv_resetsinglecounter(PgStat_MsgResetsinglecounter *msg, int len)
 {
    PgStat_StatDBEntry *dbentry;
 
-   dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
+   if (IsSharedRelation(msg->m_objectid))
+       dbentry = pgstat_get_db_entry(InvalidOid, false);
+   else
+       dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
 
    if (!dbentry)
        return;
index 21b6648f5ad8da24a7aa9f0ecf3b8eb299fb1249..e0f90c9d8e497a991381a3bfaf8c2eb44500c5e6 100644 (file)
@@ -53,6 +53,6 @@
  */
 
 /*                         yyyymmddN */
-#define CATALOG_VERSION_NO 202108311
+#define CATALOG_VERSION_NO 202109021
 
 #endif
index 4f170eaf48c2bb6f974461fbfa4d0a7410cd43b4..1a750a49ca70cfea555271c5cd94e3bc39dacae8 100644 (file)
   proname => 'pg_stat_reset_shared', provolatile => 'v', prorettype => 'void',
   proargtypes => 'text', prosrc => 'pg_stat_reset_shared' },
 { oid => '3776',
-  descr => 'statistics: reset collected statistics for a single table or index in the current database',
+  descr => 'statistics: reset collected statistics for a single table or index in the current database or shared across all databases in the cluster',
   proname => 'pg_stat_reset_single_table_counters', provolatile => 'v',
   prorettype => 'void', proargtypes => 'oid',
   prosrc => 'pg_stat_reset_single_table_counters' },