@@ -124,7 +124,7 @@ static bool pgstat_write_statsfile_needed(void);
124
124
static bool pgstat_db_requested (Oid databaseid );
125
125
126
126
static PgStat_StatReplSlotEntry * pgstat_get_replslot_entry (NameData name , bool create_it );
127
- static void pgstat_reset_replslot (PgStat_StatReplSlotEntry * slotstats , TimestampTz ts );
127
+ static void pgstat_reset_replslot_entry (PgStat_StatReplSlotEntry * slotstats , TimestampTz ts );
128
128
129
129
static HTAB * pgstat_collect_oids (Oid catalogid , AttrNumber anum_oid );
130
130
@@ -1084,55 +1084,110 @@ pgstat_reset_counters(void)
1084
1084
}
1085
1085
1086
1086
/*
1087
- * Reset a single counter.
1087
+ * Reset a single variable-numbered entry.
1088
+ *
1089
+ * If the stats kind is within a database, also reset the database's
1090
+ * stat_reset_timestamp.
1088
1091
*
1089
1092
* Permission checking for this function is managed through the normal
1090
1093
* GRANT system.
1091
1094
*/
1092
1095
void
1093
- pgstat_reset_single_counter ( Oid objoid , PgStat_Single_Reset_Type type )
1096
+ pgstat_reset ( PgStat_Kind kind , Oid dboid , Oid objoid )
1094
1097
{
1095
- PgStat_MsgResetsinglecounter msg ;
1096
1098
1097
1099
if (pgStatSock == PGINVALID_SOCKET )
1098
1100
return ;
1099
1101
1100
- pgstat_setheader (& msg .m_hdr , PGSTAT_MTYPE_RESETSINGLECOUNTER );
1101
- msg .m_databaseid = MyDatabaseId ;
1102
- msg .m_resettype = type ;
1103
- msg .m_objectid = objoid ;
1102
+ switch (kind )
1103
+ {
1104
+ case PGSTAT_KIND_FUNCTION :
1105
+ case PGSTAT_KIND_RELATION :
1106
+ {
1107
+ PgStat_MsgResetsinglecounter msg ;
1104
1108
1105
- pgstat_send (& msg , sizeof (msg ));
1109
+ pgstat_setheader (& msg .m_hdr , PGSTAT_MTYPE_RESETSINGLECOUNTER );
1110
+ msg .m_databaseid = dboid ;
1111
+ msg .m_resettype = kind ;
1112
+ msg .m_objectid = objoid ;
1113
+ pgstat_send (& msg , sizeof (msg ));
1114
+ }
1115
+ break ;
1116
+
1117
+ case PGSTAT_KIND_SUBSCRIPTION :
1118
+ {
1119
+ PgStat_MsgResetsubcounter msg ;
1120
+
1121
+ Assert (dboid == InvalidOid );
1122
+ msg .m_subid = objoid ;
1123
+ pgstat_setheader (& msg .m_hdr , PGSTAT_MTYPE_RESETSUBCOUNTER );
1124
+ }
1125
+ break ;
1126
+
1127
+ default :
1128
+ elog (ERROR , "unexpected" );
1129
+ }
1106
1130
}
1107
1131
1108
1132
/*
1109
- * Reset cluster-wide shared counters .
1133
+ * Reset stats for all entries of a kind .
1110
1134
*
1111
1135
* Permission checking for this function is managed through the normal
1112
1136
* GRANT system.
1113
1137
*/
1114
1138
void
1115
- pgstat_reset_shared_counters ( const char * target )
1139
+ pgstat_reset_of_kind ( PgStat_Kind kind )
1116
1140
{
1117
- PgStat_MsgResetsharedcounter msg ;
1118
-
1119
1141
if (pgStatSock == PGINVALID_SOCKET )
1120
1142
return ;
1121
1143
1122
- if (strcmp (target , "archiver" ) == 0 )
1123
- msg .m_resettarget = RESET_ARCHIVER ;
1124
- else if (strcmp (target , "bgwriter" ) == 0 )
1125
- msg .m_resettarget = RESET_BGWRITER ;
1126
- else if (strcmp (target , "wal" ) == 0 )
1127
- msg .m_resettarget = RESET_WAL ;
1128
- else
1129
- ereport (ERROR ,
1130
- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
1131
- errmsg ("unrecognized reset target: \"%s\"" , target ),
1132
- errhint ("Target must be \"archiver\", \"bgwriter\", or \"wal\"." )));
1144
+ switch (kind )
1145
+ {
1146
+ case PGSTAT_KIND_ARCHIVER :
1147
+ case PGSTAT_KIND_BGWRITER :
1148
+ case PGSTAT_KIND_CHECKPOINTER :
1149
+ case PGSTAT_KIND_WAL :
1150
+ {
1151
+ PgStat_MsgResetsharedcounter msg ;
1133
1152
1134
- pgstat_setheader (& msg .m_hdr , PGSTAT_MTYPE_RESETSHAREDCOUNTER );
1135
- pgstat_send (& msg , sizeof (msg ));
1153
+ pgstat_setheader (& msg .m_hdr , PGSTAT_MTYPE_RESETSHAREDCOUNTER );
1154
+ msg .m_resettarget = kind ;
1155
+ pgstat_send (& msg , sizeof (msg ));
1156
+ }
1157
+ break ;
1158
+ case PGSTAT_KIND_SLRU :
1159
+ {
1160
+ PgStat_MsgResetslrucounter msg ;
1161
+
1162
+ pgstat_setheader (& msg .m_hdr , PGSTAT_MTYPE_RESETSLRUCOUNTER );
1163
+ msg .m_index = -1 ;
1164
+ pgstat_send (& msg , sizeof (msg ));
1165
+ }
1166
+ break ;
1167
+ case PGSTAT_KIND_REPLSLOT :
1168
+ {
1169
+ PgStat_MsgResetreplslotcounter msg ;
1170
+
1171
+ pgstat_setheader (& msg .m_hdr , PGSTAT_MTYPE_RESETREPLSLOTCOUNTER );
1172
+ msg .clearall = true;
1173
+ pgstat_send (& msg , sizeof (msg ));
1174
+ }
1175
+ break ;
1176
+
1177
+ case PGSTAT_KIND_SUBSCRIPTION :
1178
+ {
1179
+ PgStat_MsgResetsubcounter msg ;
1180
+
1181
+ msg .m_subid = InvalidOid ;
1182
+ pgstat_setheader (& msg .m_hdr , PGSTAT_MTYPE_RESETSUBCOUNTER );
1183
+
1184
+ pgstat_send (& msg , sizeof (msg ));
1185
+ }
1186
+ break ;
1187
+
1188
+ default :
1189
+ elog (ERROR , "unexpected" );
1190
+ }
1136
1191
}
1137
1192
1138
1193
/*
@@ -1954,7 +2009,7 @@ pgstat_get_replslot_entry(NameData name, bool create)
1954
2009
if (create && !found )
1955
2010
{
1956
2011
namestrcpy (& (slotent -> slotname ), NameStr (name ));
1957
- pgstat_reset_replslot (slotent , 0 );
2012
+ pgstat_reset_replslot_entry (slotent , 0 );
1958
2013
}
1959
2014
1960
2015
return slotent ;
@@ -1964,7 +2019,7 @@ pgstat_get_replslot_entry(NameData name, bool create)
1964
2019
* Reset the given replication slot stats.
1965
2020
*/
1966
2021
static void
1967
- pgstat_reset_replslot (PgStat_StatReplSlotEntry * slotent , TimestampTz ts )
2022
+ pgstat_reset_replslot_entry (PgStat_StatReplSlotEntry * slotent , TimestampTz ts )
1968
2023
{
1969
2024
/* reset only counters. Don't clear slot name */
1970
2025
slotent -> spill_txns = 0 ;
@@ -3528,7 +3583,8 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len)
3528
3583
static void
3529
3584
pgstat_recv_resetsharedcounter (PgStat_MsgResetsharedcounter * msg , int len )
3530
3585
{
3531
- if (msg -> m_resettarget == RESET_BGWRITER )
3586
+ if (msg -> m_resettarget == PGSTAT_KIND_BGWRITER ||
3587
+ msg -> m_resettarget == PGSTAT_KIND_CHECKPOINTER )
3532
3588
{
3533
3589
/*
3534
3590
* Reset the global, bgwriter and checkpointer statistics for the
@@ -3537,13 +3593,13 @@ pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len)
3537
3593
memset (& globalStats , 0 , sizeof (globalStats ));
3538
3594
globalStats .bgwriter .stat_reset_timestamp = GetCurrentTimestamp ();
3539
3595
}
3540
- else if (msg -> m_resettarget == RESET_ARCHIVER )
3596
+ else if (msg -> m_resettarget == PGSTAT_KIND_ARCHIVER )
3541
3597
{
3542
3598
/* Reset the archiver statistics for the cluster. */
3543
3599
memset (& archiverStats , 0 , sizeof (archiverStats ));
3544
3600
archiverStats .stat_reset_timestamp = GetCurrentTimestamp ();
3545
3601
}
3546
- else if (msg -> m_resettarget == RESET_WAL )
3602
+ else if (msg -> m_resettarget == PGSTAT_KIND_WAL )
3547
3603
{
3548
3604
/* Reset the WAL statistics for the cluster. */
3549
3605
memset (& walStats , 0 , sizeof (walStats ));
@@ -3577,10 +3633,10 @@ pgstat_recv_resetsinglecounter(PgStat_MsgResetsinglecounter *msg, int len)
3577
3633
dbentry -> stat_reset_timestamp = GetCurrentTimestamp ();
3578
3634
3579
3635
/* Remove object if it exists, ignore it if not */
3580
- if (msg -> m_resettype == RESET_TABLE )
3636
+ if (msg -> m_resettype == PGSTAT_KIND_RELATION )
3581
3637
(void ) hash_search (dbentry -> tables , (void * ) & (msg -> m_objectid ),
3582
3638
HASH_REMOVE , NULL );
3583
- else if (msg -> m_resettype == RESET_FUNCTION )
3639
+ else if (msg -> m_resettype == PGSTAT_KIND_FUNCTION )
3584
3640
(void ) hash_search (dbentry -> functions , (void * ) & (msg -> m_objectid ),
3585
3641
HASH_REMOVE , NULL );
3586
3642
}
@@ -3626,7 +3682,7 @@ pgstat_recv_resetreplslotcounter(PgStat_MsgResetreplslotcounter *msg,
3626
3682
3627
3683
hash_seq_init (& sstat , replSlotStatHash );
3628
3684
while ((slotent = (PgStat_StatReplSlotEntry * ) hash_seq_search (& sstat )) != NULL )
3629
- pgstat_reset_replslot (slotent , ts );
3685
+ pgstat_reset_replslot_entry (slotent , ts );
3630
3686
}
3631
3687
else
3632
3688
{
@@ -3643,7 +3699,7 @@ pgstat_recv_resetreplslotcounter(PgStat_MsgResetreplslotcounter *msg,
3643
3699
return ;
3644
3700
3645
3701
/* Reset the stats for the requested replication slot */
3646
- pgstat_reset_replslot (slotent , ts );
3702
+ pgstat_reset_replslot_entry (slotent , ts );
3647
3703
}
3648
3704
}
3649
3705
@@ -3963,7 +4019,7 @@ pgstat_recv_replslot(PgStat_MsgReplSlot *msg, int len)
3963
4019
* lost, slotent has stats for the old slot. So we initialize all
3964
4020
* counters at slot creation.
3965
4021
*/
3966
- pgstat_reset_replslot (slotent , 0 );
4022
+ pgstat_reset_replslot_entry (slotent , 0 );
3967
4023
}
3968
4024
else
3969
4025
{
0 commit comments