Resetting a single statistics counter
In the spirit of finishing off small patches, attached is the one that
implements pg_stat_reset_single(), to be able to reset stats for a
single table or function. I kind of thought it would be included in
the patch from Greg Smith for shared counters so I put it aside, but I
guess I misunderstood him there. Anyway, I polished off the final
part, and here it is.
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
Attachments:
resetsingle.patchapplication/octet-stream; name=resetsingle.patchDownload
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index b1c0a1b..f060bd2 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -929,6 +929,15 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
<structname>pg_stat_bgwriter</>.
</entry>
</row>
+
+ <row>
+ <entry><literal><function>pg_stat_reset_single</function>(oid)</literal></entry>
+ <entry><type>void</type></entry>
+ <entry>
+ Reset statistics for a single object (table, index or function) in the
+ current database to zero (requires superuser privileges)
+ </entry>
+ </row>
</tbody>
</tgroup>
</table>
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 36d0872..72b4ce8 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -271,6 +271,7 @@ static void pgstat_recv_tabpurge(PgStat_MsgTabpurge *msg, int len);
static void pgstat_recv_dropdb(PgStat_MsgDropdb *msg, int len);
static void pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len);
static void pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len);
+static void pgstat_recv_resetsinglecounter(PgStat_MsgResetsinglecounter *msg, int len);
static void pgstat_recv_autovac(PgStat_MsgAutovacStart *msg, int len);
static void pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len);
static void pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len);
@@ -1188,6 +1189,31 @@ pgstat_reset_shared_counters(const char *target)
}
/* ----------
+ * pgstat_reset_single_counter() -
+ *
+ * Tell the statistics collector to reset a single counter.
+ * ----------
+ */
+void pgstat_reset_single_counter(Oid objoid)
+{
+ PgStat_MsgResetsinglecounter msg;
+
+ if (pgStatSock < 0)
+ return;
+
+ if (!superuser())
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("must be superuser to reset statistics counters")));
+
+ pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_RESETSINGLECOUNTER);
+ msg.m_databaseid = MyDatabaseId;
+ msg.m_objectid = objoid;
+
+ pgstat_send(&msg, sizeof(msg));
+}
+
+/* ----------
* pgstat_report_autovac() -
*
* Called from autovacuum.c to report startup of an autovacuum process.
@@ -2954,6 +2980,12 @@ PgstatCollectorMain(int argc, char *argv[])
len);
break;
+ case PGSTAT_MTYPE_RESETSINGLECOUNTER:
+ pgstat_recv_resetsinglecounter(
+ (PgStat_MsgResetsinglecounter *) &msg,
+ len);
+ break;
+
case PGSTAT_MTYPE_AUTOVAC_START:
pgstat_recv_autovac((PgStat_MsgAutovacStart *) &msg, len);
break;
@@ -3929,6 +3961,28 @@ pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len)
}
/* ----------
+ * pgstat_recv_resetsinglecounter() -
+ *
+ * Reset a statistics for a single object
+ * ----------
+ */
+static void
+pgstat_recv_resetsinglecounter(PgStat_MsgResetsinglecounter *msg, int len)
+{
+ PgStat_StatDBEntry *dbentry;
+
+ dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
+
+ if (!dbentry)
+ return;
+
+
+ /* Remove object if it exists, ignore it if not */
+ (void) hash_search(dbentry->tables, (void *) &(msg->m_objectid), HASH_REMOVE, NULL);
+ (void) hash_search(dbentry->functions, (void *)&(msg->m_objectid), HASH_REMOVE, NULL);
+}
+
+/* ----------
* pgstat_recv_autovac() -
*
* Process an autovacuum signalling message.
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index f6cf566..4d6259d 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -79,6 +79,7 @@ extern Datum pg_stat_get_buf_alloc(PG_FUNCTION_ARGS);
extern Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS);
extern Datum pg_stat_reset(PG_FUNCTION_ARGS);
extern Datum pg_stat_reset_shared(PG_FUNCTION_ARGS);
+extern Datum pg_stat_reset_single(PG_FUNCTION_ARGS);
/* Global bgwriter statistics, from bgwriter.c */
extern PgStat_MsgBgWriter bgwriterStats;
@@ -1120,3 +1121,12 @@ pg_stat_reset_shared(PG_FUNCTION_ARGS)
PG_RETURN_VOID();
}
+
+/* Reset a a single counter in the current database */
+Datum
+pg_stat_reset_single(PG_FUNCTION_ARGS)
+{
+ pgstat_reset_single_counter(PG_GETARG_OID(0));
+
+ PG_RETURN_VOID();
+}
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index c4320e5..01232f1 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -3075,6 +3075,8 @@ DATA(insert OID = 2274 ( pg_stat_reset PGNSP PGUID 12 1 0 0 f f f f f v 0 0
DESCR("statistics: reset collected statistics for current database");
DATA(insert OID = 3775 ( pg_stat_reset_shared PGNSP PGUID 12 1 0 0 f f f f f v 1 0 2278 "25" _null_ _null_ _null_ _null_ pg_stat_reset_shared _null_ _null_ _null_ ));
DESCR("statistics: reset collected statistics shared across the cluster");
+DATA(insert OID = 3776 ( pg_stat_reset_single PGNSP PGUID 12 1 0 0 f f f f f v 1 0 2278 "26" _null_ _null_ _null_ _null_ pg_stat_reset_single _null_ _null_ _null_ ));
+DESCR("statistics: reset collected statistics for a single object in the current database");
DATA(insert OID = 1946 ( encode PGNSP PGUID 12 1 0 0 f f f t f i 2 0 25 "17 25" _null_ _null_ _null_ _null_ binary_encode _null_ _null_ _null_ ));
DESCR("convert bytea value into some ascii-only text string");
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index c3de665..dd9b899 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -39,6 +39,7 @@ typedef enum StatMsgType
PGSTAT_MTYPE_DROPDB,
PGSTAT_MTYPE_RESETCOUNTER,
PGSTAT_MTYPE_RESETSHAREDCOUNTER,
+ PGSTAT_MTYPE_RESETSINGLECOUNTER,
PGSTAT_MTYPE_AUTOVAC_START,
PGSTAT_MTYPE_VACUUM,
PGSTAT_MTYPE_ANALYZE,
@@ -279,6 +280,18 @@ typedef struct PgStat_MsgResetsharedcounter
} PgStat_MsgResetsharedcounter;
/* ----------
+ * PgStat_MsgResetsinglecounter Sent by the backend to tell the collector
+ * to reset a single counter
+ * ----------
+ */
+typedef struct PgStat_MsgResetsinglecounter
+{
+ PgStat_MsgHdr m_hdr;
+ Oid m_databaseid;
+ Oid m_objectid;
+} PgStat_MsgResetsinglecounter;
+
+/* ----------
* PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal
* that a database is going to be processed
* ----------
@@ -432,6 +445,7 @@ typedef union PgStat_Msg
PgStat_MsgDropdb msg_dropdb;
PgStat_MsgResetcounter msg_resetcounter;
PgStat_MsgResetsharedcounter msg_resetsharedcounter;
+ PgStat_MsgResetsinglecounter msg_resetsinglecounter;
PgStat_MsgAutovacStart msg_autovacuum;
PgStat_MsgVacuum msg_vacuum;
PgStat_MsgAnalyze msg_analyze;
@@ -654,6 +668,7 @@ extern void pgstat_drop_database(Oid databaseid);
extern void pgstat_clear_snapshot(void);
extern void pgstat_reset_counters(void);
extern void pgstat_reset_shared_counters(const char *);
+extern void pgstat_reset_single_counter(Oid objectid);
extern void pgstat_report_autovac(Oid dboid);
extern void pgstat_report_vacuum(Oid tableoid, bool shared, bool adopt_counts,
Magnus Hagander <magnus@hagander.net> writes:
In the spirit of finishing off small patches, attached is the one that
implements pg_stat_reset_single(), to be able to reset stats for a
single table or function. I kind of thought it would be included in
the patch from Greg Smith for shared counters so I put it aside, but I
guess I misunderstood him there. Anyway, I polished off the final
part, and here it is.
This is bogus; it assumes tables and functions will not have the same
OIDs.
regards, tom lane
2010/1/24 Tom Lane <tgl@sss.pgh.pa.us>:
Magnus Hagander <magnus@hagander.net> writes:
In the spirit of finishing off small patches, attached is the one that
implements pg_stat_reset_single(), to be able to reset stats for a
single table or function. I kind of thought it would be included in
the patch from Greg Smith for shared counters so I put it aside, but I
guess I misunderstood him there. Anyway, I polished off the final
part, and here it is.This is bogus; it assumes tables and functions will not have the same
OIDs.
Gah... *faceinpalms*
Off to make it two separate functions.. (seems much more user-friendly
than a single function with an extra argument, IMHO)
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
On Sun, 2010-01-24 at 18:25 +0100, Magnus Hagander wrote:
2010/1/24 Tom Lane <tgl@sss.pgh.pa.us>:
Magnus Hagander <magnus@hagander.net> writes:
In the spirit of finishing off small patches, attached is the one that
implements pg_stat_reset_single(), to be able to reset stats for a
single table or function. I kind of thought it would be included in
the patch from Greg Smith for shared counters so I put it aside, but I
guess I misunderstood him there. Anyway, I polished off the final
part, and here it is.This is bogus; it assumes tables and functions will not have the same
OIDs.Gah... *faceinpalms*
Off to make it two separate functions.. (seems much more user-friendly
than a single function with an extra argument, IMHO)
And a much better name also :-)
--
Simon Riggs www.2ndQuadrant.com
2010/1/24 Magnus Hagander <magnus@hagander.net>:
2010/1/24 Tom Lane <tgl@sss.pgh.pa.us>:
Magnus Hagander <magnus@hagander.net> writes:
In the spirit of finishing off small patches, attached is the one that
implements pg_stat_reset_single(), to be able to reset stats for a
single table or function. I kind of thought it would be included in
the patch from Greg Smith for shared counters so I put it aside, but I
guess I misunderstood him there. Anyway, I polished off the final
part, and here it is.This is bogus; it assumes tables and functions will not have the same
OIDs.Gah... *faceinpalms*
Off to make it two separate functions.. (seems much more user-friendly
than a single function with an extra argument, IMHO)
Here goes.
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
Attachments:
resetsingle.patchapplication/octet-stream; name=resetsingle.patchDownload
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index b1c0a1b..8b5b70e 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -929,6 +929,24 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
<structname>pg_stat_bgwriter</>.
</entry>
</row>
+
+ <row>
+ <entry><literal><function>pg_stat_reset_single_table</function>(oid)</literal></entry>
+ <entry><type>void</type></entry>
+ <entry>
+ Reset statistics for a single table or index in the current database to
+ zero (requires superuser privileges)
+ </entry>
+ </row>
+
+ <row>
+ <entry><literal><function>pg_stat_reset_single_function</function>(oid)</literal></entry>
+ <entry><type>void</type></entry>
+ <entry>
+ Reset statistics for a single function in the current database to
+ zero (requires superuser privileges)
+ </entry>
+ </row>
</tbody>
</tgroup>
</table>
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 36d0872..474e785 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -271,6 +271,7 @@ static void pgstat_recv_tabpurge(PgStat_MsgTabpurge *msg, int len);
static void pgstat_recv_dropdb(PgStat_MsgDropdb *msg, int len);
static void pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len);
static void pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len);
+static void pgstat_recv_resetsinglecounter(PgStat_MsgResetsinglecounter *msg, int len);
static void pgstat_recv_autovac(PgStat_MsgAutovacStart *msg, int len);
static void pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len);
static void pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len);
@@ -1188,6 +1189,32 @@ pgstat_reset_shared_counters(const char *target)
}
/* ----------
+ * pgstat_reset_single_counter() -
+ *
+ * Tell the statistics collector to reset a single counter.
+ * ----------
+ */
+void pgstat_reset_single_counter(Oid objoid, PgStat_Single_Reset_Type type)
+{
+ PgStat_MsgResetsinglecounter msg;
+
+ if (pgStatSock < 0)
+ return;
+
+ if (!superuser())
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("must be superuser to reset statistics counters")));
+
+ pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_RESETSINGLECOUNTER);
+ msg.m_databaseid = MyDatabaseId;
+ msg.m_resettype = type;
+ msg.m_objectid = objoid;
+
+ pgstat_send(&msg, sizeof(msg));
+}
+
+/* ----------
* pgstat_report_autovac() -
*
* Called from autovacuum.c to report startup of an autovacuum process.
@@ -2954,6 +2981,12 @@ PgstatCollectorMain(int argc, char *argv[])
len);
break;
+ case PGSTAT_MTYPE_RESETSINGLECOUNTER:
+ pgstat_recv_resetsinglecounter(
+ (PgStat_MsgResetsinglecounter *) &msg,
+ len);
+ break;
+
case PGSTAT_MTYPE_AUTOVAC_START:
pgstat_recv_autovac((PgStat_MsgAutovacStart *) &msg, len);
break;
@@ -3929,6 +3962,30 @@ pgstat_recv_resetsharedcounter(PgStat_MsgResetsharedcounter *msg, int len)
}
/* ----------
+ * pgstat_recv_resetsinglecounter() -
+ *
+ * Reset a statistics for a single object
+ * ----------
+ */
+static void
+pgstat_recv_resetsinglecounter(PgStat_MsgResetsinglecounter *msg, int len)
+{
+ PgStat_StatDBEntry *dbentry;
+
+ dbentry = pgstat_get_db_entry(msg->m_databaseid, false);
+
+ if (!dbentry)
+ return;
+
+
+ /* Remove object if it exists, ignore it if not */
+ if (msg->m_resettype == RESET_TABLE)
+ (void) hash_search(dbentry->tables, (void *) &(msg->m_objectid), HASH_REMOVE, NULL);
+ else if (msg->m_resettype == RESET_FUNCTION)
+ (void) hash_search(dbentry->functions, (void *)&(msg->m_objectid), HASH_REMOVE, NULL);
+}
+
+/* ----------
* pgstat_recv_autovac() -
*
* Process an autovacuum signalling message.
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index f6cf566..f6cb55d 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -79,6 +79,8 @@ extern Datum pg_stat_get_buf_alloc(PG_FUNCTION_ARGS);
extern Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS);
extern Datum pg_stat_reset(PG_FUNCTION_ARGS);
extern Datum pg_stat_reset_shared(PG_FUNCTION_ARGS);
+extern Datum pg_stat_reset_single_table(PG_FUNCTION_ARGS);
+extern Datum pg_stat_reset_single_function(PG_FUNCTION_ARGS);
/* Global bgwriter statistics, from bgwriter.c */
extern PgStat_MsgBgWriter bgwriterStats;
@@ -1120,3 +1122,20 @@ pg_stat_reset_shared(PG_FUNCTION_ARGS)
PG_RETURN_VOID();
}
+
+/* Reset a a single counter in the current database */
+Datum
+pg_stat_reset_single_table(PG_FUNCTION_ARGS)
+{
+ pgstat_reset_single_counter(PG_GETARG_OID(0), RESET_TABLE);
+
+ PG_RETURN_VOID();
+}
+
+Datum
+pg_stat_reset_single_function(PG_FUNCTION_ARGS)
+{
+ pgstat_reset_single_counter(PG_GETARG_OID(0), RESET_FUNCTION);
+
+ PG_RETURN_VOID();
+}
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index c4320e5..cc71aa6 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -3075,6 +3075,10 @@ DATA(insert OID = 2274 ( pg_stat_reset PGNSP PGUID 12 1 0 0 f f f f f v 0 0
DESCR("statistics: reset collected statistics for current database");
DATA(insert OID = 3775 ( pg_stat_reset_shared PGNSP PGUID 12 1 0 0 f f f f f v 1 0 2278 "25" _null_ _null_ _null_ _null_ pg_stat_reset_shared _null_ _null_ _null_ ));
DESCR("statistics: reset collected statistics shared across the cluster");
+DATA(insert OID = 3776 ( pg_stat_reset_single_table PGNSP PGUID 12 1 0 0 f f f f f v 1 0 2278 "26" _null_ _null_ _null_ _null_ pg_stat_reset_single_table _null_ _null_ _null_ ));
+DESCR("statistics: reset collected statistics for a single table or index in the current database");
+DATA(insert OID = 3777 ( pg_stat_reset_single_function PGNSP PGUID 12 1 0 0 f f f f f v 1 0 2278 "26" _null_ _null_ _null_ _null_ pg_stat_reset_single_function _null_ _null_ _null_ ));
+DESCR("statistics: reset collected statistics for a single function in the current database");
DATA(insert OID = 1946 ( encode PGNSP PGUID 12 1 0 0 f f f t f i 2 0 25 "17 25" _null_ _null_ _null_ _null_ binary_encode _null_ _null_ _null_ ));
DESCR("convert bytea value into some ascii-only text string");
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index c3de665..90915a2 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -39,6 +39,7 @@ typedef enum StatMsgType
PGSTAT_MTYPE_DROPDB,
PGSTAT_MTYPE_RESETCOUNTER,
PGSTAT_MTYPE_RESETSHAREDCOUNTER,
+ PGSTAT_MTYPE_RESETSINGLECOUNTER,
PGSTAT_MTYPE_AUTOVAC_START,
PGSTAT_MTYPE_VACUUM,
PGSTAT_MTYPE_ANALYZE,
@@ -100,6 +101,12 @@ typedef enum PgStat_Shared_Reset_Target
RESET_BGWRITER
} PgStat_Shared_Reset_Target;
+/* Possible object types for resetting single counters */
+typedef enum PgStat_Single_Reset_Type
+{
+ RESET_TABLE,
+ RESET_FUNCTION
+} PgStat_Single_Reset_Type;
/* ------------------------------------------------------------
* Structures kept in backend local memory while accumulating counts
@@ -279,6 +286,19 @@ typedef struct PgStat_MsgResetsharedcounter
} PgStat_MsgResetsharedcounter;
/* ----------
+ * PgStat_MsgResetsinglecounter Sent by the backend to tell the collector
+ * to reset a single counter
+ * ----------
+ */
+typedef struct PgStat_MsgResetsinglecounter
+{
+ PgStat_MsgHdr m_hdr;
+ Oid m_databaseid;
+ PgStat_Single_Reset_Type m_resettype;
+ Oid m_objectid;
+} PgStat_MsgResetsinglecounter;
+
+/* ----------
* PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal
* that a database is going to be processed
* ----------
@@ -432,6 +452,7 @@ typedef union PgStat_Msg
PgStat_MsgDropdb msg_dropdb;
PgStat_MsgResetcounter msg_resetcounter;
PgStat_MsgResetsharedcounter msg_resetsharedcounter;
+ PgStat_MsgResetsinglecounter msg_resetsinglecounter;
PgStat_MsgAutovacStart msg_autovacuum;
PgStat_MsgVacuum msg_vacuum;
PgStat_MsgAnalyze msg_analyze;
@@ -654,6 +675,7 @@ extern void pgstat_drop_database(Oid databaseid);
extern void pgstat_clear_snapshot(void);
extern void pgstat_reset_counters(void);
extern void pgstat_reset_shared_counters(const char *);
+extern void pgstat_reset_single_counter(Oid objectid, PgStat_Single_Reset_Type type);
extern void pgstat_report_autovac(Oid dboid);
extern void pgstat_report_vacuum(Oid tableoid, bool shared, bool adopt_counts,
Magnus Hagander escreveu:
Off to make it two separate functions.. (seems much more user-friendly
than a single function with an extra argument, IMHO)
+1. But as Simon said _single_ is too ugly. What about
pg_stat_reset_user_{function,relation}?
Another thing that is not a problem of your patch but it needs to be fixed is
that resetting functions remove the line from pg_stat_user_functions; that a
different behavior from other pg_stat_user_* functions.
--
Euler Taveira de Oliveira
http://www.timbira.com/
Magnus Hagander <magnus@hagander.net> writes:
Here goes.
Looks much saner. One minor stylistic gripe:
+Datum
+pg_stat_reset_single_table(PG_FUNCTION_ARGS)
+{
+ pgstat_reset_single_counter(PG_GETARG_OID(0), RESET_TABLE);
+
+ PG_RETURN_VOID();
+}
I don't like sticking PG_GETARG calls inline in the body of a V1-protocol
function, even in trivial cases like this. I think better style is
Oid taboid = PG_GETARG_OID(0);
pgstat_reset_single_counter(taboid, RESET_TABLE);
This approach associates a clear name and type with each argument,
thereby helping to buy back some of the readability we lose by not
being able to use regular C function declarations. When we designed
the V1 call protocol, I had hoped we might someday have scripts that
would crosscheck such declarations against the pg_proc contents, and
I still haven't entirely given up that idea ...
regards, tom lane
Euler Taveira de Oliveira <euler@timbira.com> writes:
Magnus Hagander escreveu:
Off to make it two separate functions.. (seems much more user-friendly
than a single function with an extra argument, IMHO)
+1. But as Simon said _single_ is too ugly. What about
pg_stat_reset_user_{function,relation}?
That implies that the operations wouldn't work against system tables;
which they do. I think a bigger problem is that "reset_single_table"
seems like it might be talking about something like a TRUNCATE, ie,
it's not clear that it means to reset counters rather than data.
The pg_stat_ prefix is some help but not enough IMO. So I suggest
pg_stat_reset_table_counters and pg_stat_reset_function_counters.
(BTW, a similar complaint could be made about the previously committed
patch: reset shared what?)
regards, tom lane
2010/1/24 Tom Lane <tgl@sss.pgh.pa.us>:
Euler Taveira de Oliveira <euler@timbira.com> writes:
Magnus Hagander escreveu:
Off to make it two separate functions.. (seems much more user-friendly
than a single function with an extra argument, IMHO)+1. But as Simon said _single_ is too ugly. What about
pg_stat_reset_user_{function,relation}?That implies that the operations wouldn't work against system tables;
which they do. I think a bigger problem is that "reset_single_table"
seems like it might be talking about something like a TRUNCATE, ie,
it's not clear that it means to reset counters rather than data.
The pg_stat_ prefix is some help but not enough IMO. So I suggest
pg_stat_reset_table_counters and pg_stat_reset_function_counters.
Doesn't the pg_stat_ part already say this?
(BTW, a similar complaint could be made about the previously committed
patch: reset shared what?)
Well, it could also be made about the original pg_stat_reset()
function - reset what?
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
Magnus Hagander <magnus@hagander.net> writes:
2010/1/24 Tom Lane <tgl@sss.pgh.pa.us>:
The pg_stat_ prefix is some help but not enough IMO. �So I suggest
pg_stat_reset_table_counters and pg_stat_reset_function_counters.
Doesn't the pg_stat_ part already say this?
My objection is that "reset_table" sounds like something you do to a
table, not something you do to stats. No, I don't think the prefix is
enough to clarify that.
(BTW, a similar complaint could be made about the previously committed
patch: reset shared what?)
Well, it could also be made about the original pg_stat_reset()
function - reset what?
In that case, there's nothing but the "stat" to suggest what gets
reset, so I think it's less likely to be misleading than the current
proposals. But if we'd been designing all of these at once, yeah,
I'd have argued for a more verbose name for that one too.
regards, tom lane
2010/1/24 Tom Lane <tgl@sss.pgh.pa.us>:
Magnus Hagander <magnus@hagander.net> writes:
2010/1/24 Tom Lane <tgl@sss.pgh.pa.us>:
The pg_stat_ prefix is some help but not enough IMO. So I suggest
pg_stat_reset_table_counters and pg_stat_reset_function_counters.Doesn't the pg_stat_ part already say this?
My objection is that "reset_table" sounds like something you do to a
table, not something you do to stats. No, I don't think the prefix is
enough to clarify that.
Fair enough, I'll just add the _counters to all three functions then.
(BTW, a similar complaint could be made about the previously committed
patch: reset shared what?)Well, it could also be made about the original pg_stat_reset()
function - reset what?In that case, there's nothing but the "stat" to suggest what gets
reset, so I think it's less likely to be misleading than the current
proposals. But if we'd been designing all of these at once, yeah,
I'd have argued for a more verbose name for that one too.
Ok.
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
Tom Lane escreveu:
That implies that the operations wouldn't work against system tables;
which they do. I think a bigger problem is that "reset_single_table"
seems like it might be talking about something like a TRUNCATE, ie,
it's not clear that it means to reset counters rather than data.
The pg_stat_ prefix is some help but not enough IMO. So I suggest
pg_stat_reset_table_counters and pg_stat_reset_function_counters.
Sure, much better. +1.
(BTW, a similar complaint could be made about the previously committed
patch: reset shared what?)
BTW, what about that idea to overload pg_stat_reset()? The
pg_stat_reset_shared should be renamed to pg_stat_reset('foo') [1]http://archives.postgresql.org/pgsql-hackers/2010-01/msg01317.php where foo
is the class of objects that it is resetting. pg_stat_reset is not a so
suggestive name but that's one we already have; besides, it will be intuitive
for users.
[1]: http://archives.postgresql.org/pgsql-hackers/2010-01/msg01317.php
--
Euler Taveira de Oliveira
http://www.timbira.com/
2010/1/24 Euler Taveira de Oliveira <euler@timbira.com>:
Tom Lane escreveu:
That implies that the operations wouldn't work against system tables;
which they do. I think a bigger problem is that "reset_single_table"
seems like it might be talking about something like a TRUNCATE, ie,
it's not clear that it means to reset counters rather than data.
The pg_stat_ prefix is some help but not enough IMO. So I suggest
pg_stat_reset_table_counters and pg_stat_reset_function_counters.Sure, much better. +1.
(BTW, a similar complaint could be made about the previously committed
patch: reset shared what?)BTW, what about that idea to overload pg_stat_reset()? The
pg_stat_reset_shared should be renamed to pg_stat_reset('foo') [1] where foo
is the class of objects that it is resetting. pg_stat_reset is not a so
suggestive name but that's one we already have; besides, it will be intuitive
for users.
I think it's easier to use the way it is now. But yes, we could
overload it to make it:
pg_stat_reset() : everything, like now
pg_stat_reset('bgwriter') : what pg_stat_reset_shared() does
now. Can take more params.
pg_stat_reset('table', 'foo'::regclass); : what
pg_stat_reset_single_table_counters does now
The advantage would be fewer functions, but I still think it's easier
to use the way we have it now.
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/