Skip to content

Commit e042678

Browse files
committed
Enhance pg_stat_reset_single_table_counters function.
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
1 parent 31c389d commit e042678

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

doc/src/sgml/monitoring.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5097,7 +5097,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
50975097
</para>
50985098
<para>
50995099
Resets statistics for a single table or index in the current database
5100-
to zero.
5100+
or shared across all databases in the cluster to zero.
51015101
</para>
51025102
<para>
51035103
This function is restricted to superusers by default, but other users

src/backend/postmaster/pgstat.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "access/transam.h"
3939
#include "access/twophase_rmgr.h"
4040
#include "access/xact.h"
41+
#include "catalog/catalog.h"
4142
#include "catalog/pg_database.h"
4243
#include "catalog/pg_proc.h"
4344
#include "common/ip.h"
@@ -5140,15 +5141,19 @@ pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len)
51405141
/* ----------
51415142
* pgstat_recv_resetsinglecounter() -
51425143
*
5143-
* Reset a statistics for a single object
5144+
* Reset a statistics for a single object, which may be of current
5145+
* database or shared across all databases in the cluster.
51445146
* ----------
51455147
*/
51465148
static void
51475149
pgstat_recv_resetsinglecounter(PgStat_MsgResetsinglecounter *msg, int len)
51485150
{
51495151
PgStat_StatDBEntry *dbentry;
51505152

5151-
dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
5153+
if (IsSharedRelation(msg->m_objectid))
5154+
dbentry = pgstat_get_db_entry(InvalidOid, false);
5155+
else
5156+
dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
51525157

51535158
if (!dbentry)
51545159
return;

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 202108311
56+
#define CATALOG_VERSION_NO 202109021
5757

5858
#endif

src/include/catalog/pg_proc.dat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5754,7 +5754,7 @@
57545754
proname => 'pg_stat_reset_shared', provolatile => 'v', prorettype => 'void',
57555755
proargtypes => 'text', prosrc => 'pg_stat_reset_shared' },
57565756
{ oid => '3776',
5757-
descr => 'statistics: reset collected statistics for a single table or index in the current database',
5757+
descr => 'statistics: reset collected statistics for a single table or index in the current database or shared across all databases in the cluster',
57585758
proname => 'pg_stat_reset_single_table_counters', provolatile => 'v',
57595759
prorettype => 'void', proargtypes => 'oid',
57605760
prosrc => 'pg_stat_reset_single_table_counters' },

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy