|
13 | 13 | * |
14 | 14 | * Copyright (c) 2001-2010, PostgreSQL Global Development Group |
15 | 15 | * |
16 | | - * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.198 2010/01/19 14:11:30 mha Exp $ |
| 16 | + * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.199 2010/01/28 14:25:41 mha Exp $ |
17 | 17 | * ---------- |
18 | 18 | */ |
19 | 19 | #include "postgres.h" |
@@ -271,6 +271,7 @@ static void pgstat_recv_tabpurge(PgStat_MsgTabpurge *msg, int len); |
271 | 271 | static void pgstat_recv_dropdb(PgStat_MsgDropdb *msg, int len); |
272 | 272 | static void pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len); |
273 | 273 | static void pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len); |
| 274 | +static void pgstat_recv_resetsinglecounter(PgStat_MsgResetsinglecounter *msg, int len); |
274 | 275 | static void pgstat_recv_autovac(PgStat_MsgAutovacStart *msg, int len); |
275 | 276 | static void pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len); |
276 | 277 | static void pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len); |
@@ -1187,6 +1188,32 @@ pgstat_reset_shared_counters(const char *target) |
1187 | 1188 | pgstat_send(&msg, sizeof(msg)); |
1188 | 1189 | } |
1189 | 1190 |
|
| 1191 | +/* ---------- |
| 1192 | + * pgstat_reset_single_counter() - |
| 1193 | + * |
| 1194 | + * Tell the statistics collector to reset a single counter. |
| 1195 | + * ---------- |
| 1196 | + */ |
| 1197 | +void pgstat_reset_single_counter(Oid objoid, PgStat_Single_Reset_Type type) |
| 1198 | +{ |
| 1199 | + PgStat_MsgResetsinglecounter msg; |
| 1200 | + |
| 1201 | + if (pgStatSock < 0) |
| 1202 | + return; |
| 1203 | + |
| 1204 | + if (!superuser()) |
| 1205 | + ereport(ERROR, |
| 1206 | + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 1207 | + errmsg("must be superuser to reset statistics counters"))); |
| 1208 | + |
| 1209 | + pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_RESETSINGLECOUNTER); |
| 1210 | + msg.m_databaseid = MyDatabaseId; |
| 1211 | + msg.m_resettype = type; |
| 1212 | + msg.m_objectid = objoid; |
| 1213 | + |
| 1214 | + pgstat_send(&msg, sizeof(msg)); |
| 1215 | +} |
| 1216 | + |
1190 | 1217 | /* ---------- |
1191 | 1218 | * pgstat_report_autovac() - |
1192 | 1219 | * |
@@ -2954,6 +2981,12 @@ PgstatCollectorMain(int argc, char *argv[]) |
2954 | 2981 | len); |
2955 | 2982 | break; |
2956 | 2983 |
|
| 2984 | + case PGSTAT_MTYPE_RESETSINGLECOUNTER: |
| 2985 | + pgstat_recv_resetsinglecounter( |
| 2986 | + (PgStat_MsgResetsinglecounter *) &msg, |
| 2987 | + len); |
| 2988 | + break; |
| 2989 | + |
2957 | 2990 | case PGSTAT_MTYPE_AUTOVAC_START: |
2958 | 2991 | pgstat_recv_autovac((PgStat_MsgAutovacStart *) &msg, len); |
2959 | 2992 | break; |
@@ -3928,6 +3961,30 @@ pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len) |
3928 | 3961 | */ |
3929 | 3962 | } |
3930 | 3963 |
|
| 3964 | +/* ---------- |
| 3965 | + * pgstat_recv_resetsinglecounter() - |
| 3966 | + * |
| 3967 | + * Reset a statistics for a single object |
| 3968 | + * ---------- |
| 3969 | + */ |
| 3970 | +static void |
| 3971 | +pgstat_recv_resetsinglecounter(PgStat_MsgResetsinglecounter *msg, int len) |
| 3972 | +{ |
| 3973 | + PgStat_StatDBEntry *dbentry; |
| 3974 | + |
| 3975 | + dbentry = pgstat_get_db_entry(msg->m_databaseid, false); |
| 3976 | + |
| 3977 | + if (!dbentry) |
| 3978 | + return; |
| 3979 | + |
| 3980 | + |
| 3981 | + /* Remove object if it exists, ignore it if not */ |
| 3982 | + if (msg->m_resettype == RESET_TABLE) |
| 3983 | + (void) hash_search(dbentry->tables, (void *) &(msg->m_objectid), HASH_REMOVE, NULL); |
| 3984 | + else if (msg->m_resettype == RESET_FUNCTION) |
| 3985 | + (void) hash_search(dbentry->functions, (void *)&(msg->m_objectid), HASH_REMOVE, NULL); |
| 3986 | +} |
| 3987 | + |
3931 | 3988 | /* ---------- |
3932 | 3989 | * pgstat_recv_autovac() - |
3933 | 3990 | * |
|
0 commit comments