|
13 | 13 | *
|
14 | 14 | * Copyright (c) 2001-2010, PostgreSQL Global Development Group
|
15 | 15 | *
|
16 |
| - * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.197 2010/01/10 14:16:07 mha Exp $ |
| 16 | + * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.198 2010/01/19 14:11:30 mha Exp $ |
17 | 17 | * ----------
|
18 | 18 | */
|
19 | 19 | #include "postgres.h"
|
@@ -270,6 +270,7 @@ static void pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len);
|
270 | 270 | 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 | +static void pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len); |
273 | 274 | static void pgstat_recv_autovac(PgStat_MsgAutovacStart *msg, int len);
|
274 | 275 | static void pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len);
|
275 | 276 | static void pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len);
|
@@ -1153,6 +1154,38 @@ pgstat_reset_counters(void)
|
1153 | 1154 | pgstat_send(&msg, sizeof(msg));
|
1154 | 1155 | }
|
1155 | 1156 |
|
| 1157 | +/* ---------- |
| 1158 | + * pgstat_reset_shared_counters() - |
| 1159 | + * |
| 1160 | + * Tell the statistics collector to reset cluster-wide shared counters. |
| 1161 | + * ---------- |
| 1162 | + */ |
| 1163 | +void |
| 1164 | +pgstat_reset_shared_counters(const char *target) |
| 1165 | +{ |
| 1166 | + PgStat_MsgResetsharedcounter msg; |
| 1167 | + |
| 1168 | + if (pgStatSock < 0) |
| 1169 | + return; |
| 1170 | + |
| 1171 | + if (!superuser()) |
| 1172 | + ereport(ERROR, |
| 1173 | + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 1174 | + errmsg("must be superuser to reset statistics counters"))); |
| 1175 | + |
| 1176 | + if (strcmp(target, "bgwriter") == 0) |
| 1177 | + msg.m_resettarget = RESET_BGWRITER; |
| 1178 | + else |
| 1179 | + { |
| 1180 | + ereport(ERROR, |
| 1181 | + (errcode(ERRCODE_SYNTAX_ERROR), |
| 1182 | + errmsg("unrecognized reset target: '%s'", target), |
| 1183 | + errhint("allowed targets are 'bgwriter'."))); |
| 1184 | + } |
| 1185 | + |
| 1186 | + pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_RESETSHAREDCOUNTER); |
| 1187 | + pgstat_send(&msg, sizeof(msg)); |
| 1188 | +} |
1156 | 1189 |
|
1157 | 1190 | /* ----------
|
1158 | 1191 | * pgstat_report_autovac() -
|
@@ -2915,6 +2948,12 @@ PgstatCollectorMain(int argc, char *argv[])
|
2915 | 2948 | len);
|
2916 | 2949 | break;
|
2917 | 2950 |
|
| 2951 | + case PGSTAT_MTYPE_RESETSHAREDCOUNTER: |
| 2952 | + pgstat_recv_resetsharedcounter( |
| 2953 | + (PgStat_MsgResetsharedcounter *) &msg, |
| 2954 | + len); |
| 2955 | + break; |
| 2956 | + |
2918 | 2957 | case PGSTAT_MTYPE_AUTOVAC_START:
|
2919 | 2958 | pgstat_recv_autovac((PgStat_MsgAutovacStart *) &msg, len);
|
2920 | 2959 | break;
|
@@ -3868,6 +3907,27 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len)
|
3868 | 3907 | HASH_ELEM | HASH_FUNCTION);
|
3869 | 3908 | }
|
3870 | 3909 |
|
| 3910 | +/* ---------- |
| 3911 | + * pgstat_recv_resetshared() - |
| 3912 | + * |
| 3913 | + * Reset some shared statistics of the cluster. |
| 3914 | + * ---------- |
| 3915 | + */ |
| 3916 | +static void |
| 3917 | +pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len) |
| 3918 | +{ |
| 3919 | + if (msg->m_resettarget==RESET_BGWRITER) |
| 3920 | + { |
| 3921 | + /* Reset the global background writer statistics for the cluster. */ |
| 3922 | + memset(&globalStats, 0, sizeof(globalStats)); |
| 3923 | + } |
| 3924 | + |
| 3925 | + /* |
| 3926 | + * Presumably the sender of this message validated the target, don't |
| 3927 | + * complain here if it's not valid |
| 3928 | + */ |
| 3929 | +} |
| 3930 | + |
3871 | 3931 | /* ----------
|
3872 | 3932 | * pgstat_recv_autovac() -
|
3873 | 3933 | *
|
|
0 commit comments