From: | pgsql-kr(at)postgresql(dot)kr |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Request improve pg_stat_statements module |
Date: | 2014-02-28 07:18:48 |
Message-ID: | 20140228071848.GA14626@postgresql.kr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
I patched to add one column in pg_stat_statements module.
and sent to author but
I recived a reject mail because unknown user :(
so I am posting to this mailling.
I need a last time of query, because I want to analyse order by recent time.
this patch code below,
review please and
I wish to apply at next version.
--- diff begin
--- ../pg_stat_statements.orig/pg_stat_statements.c 2014-02-18 04:29:55.000000000 +0900
+++ pg_stat_statements.c 2014-02-28 15:34:38.000000000 +0900
@@ -59,6 +59,7 @@
#include "storage/spin.h"
#include "tcop/utility.h"
#include "utils/builtins.h"
+#include "utils/timestamp.h"
PG_MODULE_MAGIC;
@@ -116,6 +117,7 @@
double blk_read_time; /* time spent reading, in msec */
double blk_write_time; /* time spent writing, in msec */
double usage; /* usage factor */
+ TimestampTz last_executed_timestamp; /* last executed timestamp of query */
} Counters;
/*
@@ -1043,6 +1045,8 @@
e->counters.blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_read_time);
e->counters.blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_write_time);
e->counters.usage += USAGE_EXEC(total_time);
+ /* last executed timestamp */
+ e->counters.last_executed_timestamp = GetCurrentTimestamp();
SpinLockRelease(&e->mutex);
}
@@ -1069,7 +1073,8 @@
}
#define PG_STAT_STATEMENTS_COLS_V1_0 14
-#define PG_STAT_STATEMENTS_COLS 18
+#define PG_STAT_STATEMENTS_COLS_V1_1 18
+#define PG_STAT_STATEMENTS_COLS 19
/*
* Retrieve statement statistics.
@@ -1087,6 +1092,7 @@
HASH_SEQ_STATUS hash_seq;
pgssEntry *entry;
bool sql_supports_v1_1_counters = true;
+ bool sql_supports_v1_2_counters = true;
if (!pgss || !pgss_hash)
ereport(ERROR,
@@ -1107,8 +1113,12 @@
/* Build a tuple descriptor for our result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
- if (tupdesc->natts == PG_STAT_STATEMENTS_COLS_V1_0)
+ if (tupdesc->natts == PG_STAT_STATEMENTS_COLS_V1_0){
sql_supports_v1_1_counters = false;
+ sql_supports_v1_2_counters = false;
+ }
+ if (tupdesc->natts == PG_STAT_STATEMENTS_COLS_V1_1)
+ sql_supports_v1_2_counters = false;
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
oldcontext = MemoryContextSwitchTo(per_query_ctx);
@@ -1185,8 +1195,15 @@
values[i++] = Float8GetDatumFast(tmp.blk_read_time);
values[i++] = Float8GetDatumFast(tmp.blk_write_time);
}
+ // last_executed_timestamp
+ if (sql_supports_v1_2_counters)
+ values[i++] = TimestampTzGetDatum(tmp.last_executed_timestamp);
+
- Assert(i == (sql_supports_v1_1_counters ?
+ if(sql_supports_v1_2_counters)
+ Assert(i == PG_STAT_STATEMENTS_COLS);
+ else
+ Assert(i == (sql_supports_v1_1_counters ?
PG_STAT_STATEMENTS_COLS : PG_STAT_STATEMENTS_COLS_V1_0));
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
-- end of diff
From | Date | Subject | |
---|---|---|---|
Next Message | Christophe Pettus | 2014-02-28 07:36:07 | Re: jsonb and nested hstore |
Previous Message | Peter Geoghegan | 2014-02-28 07:15:23 | Re: jsonb and nested hstore |