Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support for 9.0 (not all executor hooks supported, different nu…

…mber of params when defining GUC options, different assign hook signature).
  • Loading branch information...
commit 9a4c8961d6be3c1bce344617e7f38eef28c1a989 1 parent c0b1713
@tvondra authored
View
16 META.json
@@ -2,13 +2,13 @@
"name": "query_histogram",
"abstract": "A histogram of queries",
"description": "This extension allows you to collect histogram of queries.",
- "version": "1.0.0",
+ "version": "1.1.0",
"maintainer": "Tomas Vondra <tv@fuzzy.cz>",
"license": "gpl_3",
"prereqs": {
"runtime": {
"requires": {
- "PostgreSQL": "9.1.0"
+ "PostgreSQL": "9.0.0"
}
}
},
@@ -16,6 +16,10 @@
"query_histogram": {
"file": "query_histogram--1.0.sql",
"version": "1.0.0"
+ },
+ "query_histogram": {
+ "file": "query_histogram--1.1.sql",
+ "version": "1.1.0"
}
},
"resources": {
@@ -26,16 +30,10 @@
},
"x_blog": "http://www.fuzzy.cz/en/articles/collecting-query-histogram/"
},
- "tags" : ["histogram", "monitoring"],
+ "tags" : ["histogram", "monitoring", "duration", "queries"],
"meta-spec": {
"version": "1.0.0",
"url": "http://pgxn.org/meta/spec.txt"
},
- "tags": [
- "histogram",
- "monitoring",
- "duration",
- "queries"
- ],
"release_status" : "testing"
}
View
17 query_histogram--1.1.sql
@@ -0,0 +1,17 @@
+CREATE OR REPLACE FUNCTION query_histogram( IN scale BOOLEAN DEFAULT TRUE, OUT bin_from INT, OUT bin_to INT, OUT bin_count BIGINT, OUT bin_count_pct REAL,
+ OUT bin_time DOUBLE PRECISION, OUT bin_time_pct REAL)
+ RETURNS SETOF record
+ AS 'MODULE_PATHNAME', 'query_histogram'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION query_histogram_reset()
+ RETURNS void
+ AS 'MODULE_PATHNAME', 'query_histogram_reset'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION query_histogram_get_reset()
+ RETURNS timestamp
+ AS 'MODULE_PATHNAME', 'query_histogram_get_reset'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE VIEW query_histogram AS SELECT histogram.*, round(1000000*bin_time/(CASE WHEN bin_count > 0 THEN bin_count ELSE 1 END))/1000 AS bin_time_avg FROM query_histogram(true) histogram;
View
2  query_histogram.control
@@ -1,6 +1,6 @@
# query histogram
comment = 'Provides access to query histogram.'
-default_version = '1.0'
+default_version = '1.1'
relocatable = true
module_pathname = '$libdir/query_histogram'
View
86 queryhist.c
@@ -34,10 +34,24 @@ static void histogram_shmem_shutdown(int code, Datum arg);
static void histogram_load_from_file(void);
+#if (PG_VERSION_NUM >= 90100)
static void set_histogram_bins_count_hook(int newval, void *extra);
static void set_histogram_bins_width_hook(int newval, void *extra);
static void set_histogram_sample_hook(int newval, void *extra);
static void set_histogram_type_hook(int newval, void *extra);
+#else
+static bool set_histogram_bins_count_hook(int newval, bool doit, GucSource source);
+static bool set_histogram_bins_width_hook(int newval, bool doit, GucSource source);
+static bool set_histogram_sample_hook(int newval, bool doit, GucSource source);
+static bool set_histogram_type_hook(int newval, bool doit, GucSource source);
+#endif
+
+/* return from a hook */
+#if (PG_VERSION_NUM >= 90100)
+#define HOOK_RETURN(a) return;
+#else
+#define HOOK_RETURN(a) return (a);
+#endif
static void query_hist_add_query(time_bin_t duration);
static bool query_histogram_enabled(void);
@@ -85,7 +99,6 @@ static bool histogram_is_dynamic = true;
static shmem_startup_hook_type prev_shmem_startup_hook = NULL;
static ExecutorStart_hook_type prev_ExecutorStart = NULL;
static ExecutorRun_hook_type prev_ExecutorRun = NULL;
-static ExecutorFinish_hook_type prev_ExecutorFinish = NULL;
static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
void _PG_init(void);
@@ -95,9 +108,13 @@ static void explain_ExecutorStart(QueryDesc *queryDesc, int eflags);
static void explain_ExecutorRun(QueryDesc *queryDesc,
ScanDirection direction,
long count);
-static void explain_ExecutorFinish(QueryDesc *queryDesc);
static void explain_ExecutorEnd(QueryDesc *queryDesc);
+#if (PG_VERSION_NUM >= 90100)
+static ExecutorFinish_hook_type prev_ExecutorFinish = NULL;
+static void explain_ExecutorFinish(QueryDesc *queryDesc);
+#endif
+
/* the whole histogram (info and data) */
static histogram_info_t * shared_histogram_info = NULL;
@@ -120,7 +137,9 @@ _PG_init(void)
false,
PGC_BACKEND,
0,
+#if (PG_VERSION_NUM >= 90100)
NULL,
+#endif
NULL,
NULL);
@@ -132,7 +151,9 @@ _PG_init(void)
0, 1000,
PGC_SUSET,
0,
+#if (PG_VERSION_NUM >= 90100)
NULL,
+#endif
&set_histogram_bins_count_hook,
NULL);
@@ -144,7 +165,9 @@ _PG_init(void)
1, 1000,
PGC_SUSET,
GUC_UNIT_MS,
+#if (PG_VERSION_NUM >= 90100)
NULL,
+#endif
&set_histogram_bins_width_hook,
NULL);
@@ -156,7 +179,9 @@ _PG_init(void)
1, 100,
PGC_SUSET,
0,
+#if (PG_VERSION_NUM >= 90100)
NULL,
+#endif
&set_histogram_sample_hook,
NULL);
@@ -168,7 +193,9 @@ _PG_init(void)
histogram_type_options,
PGC_SUSET,
0,
+#if (PG_VERSION_NUM >= 90100)
NULL,
+#endif
&set_histogram_type_hook,
NULL);
@@ -190,8 +217,10 @@ _PG_init(void)
ExecutorStart_hook = explain_ExecutorStart;
prev_ExecutorRun = ExecutorRun_hook;
ExecutorRun_hook = explain_ExecutorRun;
+#if (PG_VERSION_NUM >= 90100)
prev_ExecutorFinish = ExecutorFinish_hook;
ExecutorFinish_hook = explain_ExecutorFinish;
+#endif
prev_ExecutorEnd = ExecutorEnd_hook;
ExecutorEnd_hook = explain_ExecutorEnd;
@@ -207,7 +236,9 @@ _PG_fini(void)
/* Uninstall hooks. */
ExecutorStart_hook = prev_ExecutorStart;
ExecutorRun_hook = prev_ExecutorRun;
+#if (PG_VERSION_NUM >= 90100)
ExecutorFinish_hook = prev_ExecutorFinish;
+#endif
ExecutorEnd_hook = prev_ExecutorEnd;
shmem_startup_hook = prev_shmem_startup_hook;
}
@@ -266,6 +297,7 @@ explain_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long count)
PG_END_TRY();
}
+#if (PG_VERSION_NUM >= 90100)
/*
* ExecutorFinish hook: all we need do is track nesting depth
*/
@@ -288,6 +320,7 @@ explain_ExecutorFinish(QueryDesc *queryDesc)
}
PG_END_TRY();
}
+#endif
/*
* ExecutorEnd hook: log results if needed
@@ -648,12 +681,17 @@ histogram_data * query_hist_get_data(bool scale) {
}
-void set_histogram_bins_count_hook(int newval, void *extra) {
+#if (PG_VERSION_NUM >= 90100)
+static void set_histogram_bins_count_hook(int newval, void *extra) {
+#else
+static bool set_histogram_bins_count_hook(int newval, bool doit, GucSource source) {
+#endif
if (! histogram_is_dynamic) {
elog(WARNING, "The histogram is not dynamic (query_histogram.dynamic=0), so "
"it's not possible to change the number of bins.");
- return;
+
+ HOOK_RETURN(false);
}
if (shared_histogram_info) {
@@ -675,15 +713,21 @@ void set_histogram_bins_count_hook(int newval, void *extra) {
LWLockRelease(shared_histogram_info->lock);
}
+ HOOK_RETURN(true);
+
}
-static
-void set_histogram_bins_width_hook(int newval, void *extra) {
+#if (PG_VERSION_NUM >= 90100)
+static void set_histogram_bins_width_hook(int newval, void *extra) {
+#else
+static bool set_histogram_bins_width_hook(int newval, bool doit, GucSource source) {
+#endif
if (! histogram_is_dynamic) {
elog(WARNING, "The histogram is not dynamic (query_histogram.dynamic=0), so "
"it's not possible to change the bin width.");
- return;
+
+ HOOK_RETURN(false);
}
if (shared_histogram_info) {
@@ -706,15 +750,22 @@ void set_histogram_bins_width_hook(int newval, void *extra) {
LWLockRelease(shared_histogram_info->lock);
}
+ HOOK_RETURN(true);
+
}
-static
-void set_histogram_sample_hook(int newval, void *extra) {
+
+#if (PG_VERSION_NUM >= 90100)
+static void set_histogram_sample_hook(int newval, void *extra) {
+#else
+static bool set_histogram_sample_hook(int newval, bool doit, GucSource source) {
+#endif
if (! histogram_is_dynamic ) {
elog(WARNING, "The histogram is not dynamic (query_histogram.dynamic=0), so "
"it's not possible to change the sampling rate.");
- return;
+
+ HOOK_RETURN(false);
}
if (shared_histogram_info) {
@@ -724,15 +775,22 @@ void set_histogram_sample_hook(int newval, void *extra) {
LWLockRelease(shared_histogram_info->lock);
}
+ HOOK_RETURN(true);
+
}
-static
-void set_histogram_type_hook(int newval, void *extra) {
+
+#if (PG_VERSION_NUM >= 90100)
+static void set_histogram_type_hook(int newval, void *extra) {
+#else
+static bool set_histogram_type_hook(int newval, bool doit, GucSource source) {
+#endif
if (! histogram_is_dynamic) {
elog(WARNING, "The histogram is not dynamic (query_histogram.dynamic=0), so "
"it's not possible to change the histogram type.");
- return;
+
+ HOOK_RETURN(false);
}
if (shared_histogram_info) {
@@ -755,6 +813,8 @@ void set_histogram_type_hook(int newval, void *extra) {
LWLockRelease(shared_histogram_info->lock);
}
+ HOOK_RETURN(true);
+
}
static
Please sign in to comment.
Something went wrong with that request. Please try again.