diff --git a/pg_stat_monitor--1.0--2.0.sql b/pg_stat_monitor--1.0--2.0.sql index 1b7388a..6199ab3 100644 --- a/pg_stat_monitor--1.0--2.0.sql +++ b/pg_stat_monitor--1.0--2.0.sql @@ -8,6 +8,7 @@ DROP FUNCTION pgsm_create_11_view CASCADE; DROP FUNCTION pgsm_create_13_view CASCADE; DROP FUNCTION pgsm_create_14_view CASCADE; DROP FUNCTION pgsm_create_view CASCADE; +DROP FUNCTION pg_stat_monitor_settings CASCADE; -- pg_stat_monitor internal function, must not call outside from this file. CREATE FUNCTION pg_stat_monitor_internal( @@ -369,7 +370,6 @@ SELECT pgsm_create_view(); REVOKE ALL ON FUNCTION range FROM PUBLIC; REVOKE ALL ON FUNCTION get_cmd_type FROM PUBLIC; -REVOKE ALL ON FUNCTION pg_stat_monitor_settings FROM PUBLIC; REVOKE ALL ON FUNCTION decode_error_level FROM PUBLIC; REVOKE ALL ON FUNCTION pg_stat_monitor_internal FROM PUBLIC; REVOKE ALL ON FUNCTION get_histogram_timings FROM PUBLIC; diff --git a/pg_stat_monitor--2.0.sql b/pg_stat_monitor--2.0.sql index e23a4e3..ff16d71 100644 --- a/pg_stat_monitor--2.0.sql +++ b/pg_stat_monitor--2.0.sql @@ -41,31 +41,6 @@ SELECT $$ LANGUAGE SQL PARALLEL SAFE; -CREATE FUNCTION pg_stat_monitor_settings( - OUT name text, - OUT value text, - OUT default_value text, - OUT description text, - OUT minimum INTEGER, - OUT maximum INTEGER, - OUT options text, - OUT restart text -) -RETURNS SETOF record -AS 'MODULE_PATHNAME', 'pg_stat_monitor_settings' -LANGUAGE C STRICT VOLATILE PARALLEL SAFE; - -CREATE VIEW pg_stat_monitor_settings AS SELECT - name, - value, - default_value, - description, - minimum, - maximum, - options, - restart -FROM pg_stat_monitor_settings(); - CREATE FUNCTION decode_error_level(elevel int) RETURNS text AS @@ -465,7 +440,6 @@ $$ LANGUAGE plpgsql; SELECT pgsm_create_view(); REVOKE ALL ON FUNCTION range FROM PUBLIC; REVOKE ALL ON FUNCTION get_cmd_type FROM PUBLIC; -REVOKE ALL ON FUNCTION pg_stat_monitor_settings FROM PUBLIC; REVOKE ALL ON FUNCTION decode_error_level FROM PUBLIC; REVOKE ALL ON FUNCTION pg_stat_monitor_internal FROM PUBLIC; REVOKE ALL ON FUNCTION get_histogram_timings FROM PUBLIC; diff --git a/pg_stat_monitor.c b/pg_stat_monitor.c index ddf1765..88ccada 100644 --- a/pg_stat_monitor.c +++ b/pg_stat_monitor.c @@ -125,7 +125,6 @@ PG_FUNCTION_INFO_V1(pg_stat_monitor_reset); PG_FUNCTION_INFO_V1(pg_stat_monitor_1_0); PG_FUNCTION_INFO_V1(pg_stat_monitor_2_0); PG_FUNCTION_INFO_V1(pg_stat_monitor); -PG_FUNCTION_INFO_V1(pg_stat_monitor_settings); PG_FUNCTION_INFO_V1(get_histogram_timings); PG_FUNCTION_INFO_V1(pg_stat_monitor_hook_stats); @@ -3304,136 +3303,6 @@ SaveQueryText(uint64 bucketid, return true; } -Datum -pg_stat_monitor_settings(PG_FUNCTION_ARGS) -{ - ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; - TupleDesc tupdesc; - Tuplestorestate *tupstore; - MemoryContext per_query_ctx; - MemoryContext oldcontext; - int i; - - /* Safety check... */ - if (!IsSystemInitialized()) - ereport(ERROR, - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("pg_stat_monitor: must be loaded via shared_preload_libraries"))); - - /* check to see if caller supports us returning a tuplestore */ - if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo)) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("pg_stat_monitor: set-valued function called in context that cannot accept a set"))); - - /* Switch into long-lived context to construct returned data structures */ - per_query_ctx = rsinfo->econtext->ecxt_per_query_memory; - oldcontext = MemoryContextSwitchTo(per_query_ctx); - - /* Build a tuple descriptor for our result type */ - if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) - { - elog(ERROR, "pg_stat_monitor_settings: return type must be a row type"); - return (Datum) 0; - } - - if (tupdesc->natts != 8) - { - elog(ERROR, "pg_stat_monitor_settings: incorrect number of output arguments, required: 7, found %d", tupdesc->natts); - return (Datum) 0; - } - - tupstore = tuplestore_begin_heap(true, false, work_mem); - rsinfo->returnMode = SFRM_Materialize; - rsinfo->setResult = tupstore; - rsinfo->setDesc = tupdesc; - - MemoryContextSwitchTo(oldcontext); - - for (i = 0; i < MAX_SETTINGS; i++) - { - Datum values[8]; - bool nulls[8]; - int j = 0; - char options[1024] = ""; - GucVariable *conf; - - memset(values, 0, sizeof(values)); - memset(nulls, 0, sizeof(nulls)); - - conf = get_conf(i); - - values[j++] = CStringGetTextDatum(conf->guc_name); - - /* Handle current and default values. */ - switch (conf->type) - { - case PGC_ENUM: - values[j++] = CStringGetTextDatum(conf->guc_options[conf->guc_variable]); - values[j++] = CStringGetTextDatum(conf->guc_options[conf->guc_default]); - break; - - case PGC_INT: - { - char value[32]; - - sprintf(value, "%d", conf->guc_variable); - values[j++] = CStringGetTextDatum(value); - - sprintf(value, "%d", conf->guc_default); - values[j++] = CStringGetTextDatum(value); - break; - } - - case PGC_BOOL: - values[j++] = CStringGetTextDatum(conf->guc_variable ? "yes" : "no"); - values[j++] = CStringGetTextDatum(conf->guc_default ? "yes" : "no"); - break; - - default: - Assert(false); - } - - values[j++] = CStringGetTextDatum(get_conf(i)->guc_desc); - - /* Minimum and maximum displayed only for integers or real numbers. */ - if (conf->type != PGC_INT) - { - nulls[j++] = true; - nulls[j++] = true; - } - else - { - values[j++] = Int32GetDatum(get_conf(i)->guc_min); - values[j++] = Int32GetDatum(get_conf(i)->guc_max); - } - - if (conf->type == PGC_ENUM) - { - size_t i; - - strcat(options, conf->guc_options[0]); - for (i = 1; i < conf->n_options; ++i) - { - strcat(options, ", "); - strcat(options, conf->guc_options[i]); - } - } - else if (conf->type == PGC_BOOL) - { - strcat(options, "yes, no"); - } - - values[j++] = CStringGetTextDatum(options); - values[j++] = CStringGetTextDatum(get_conf(i)->guc_restart ? "yes" : "no"); - tuplestore_putvalues(tupstore, tupdesc, values, nulls); - } - /* clean up and return the tuplestore */ - tuplestore_donestoring(tupstore); - return (Datum) 0; -} - - Datum pg_stat_monitor_hook_stats(PG_FUNCTION_ARGS) { diff --git a/regression/expected/guc.out b/regression/expected/guc.out index 56bdaab..4e1fa54 100644 --- a/regression/expected/guc.out +++ b/regression/expected/guc.out @@ -1,39 +1,280 @@ CREATE EXTENSION pg_stat_monitor; -SELECT pg_stat_monitor_reset(); - pg_stat_monitor_reset ------------------------ - -(1 row) - -select pg_sleep(.5); - pg_sleep ----------- - -(1 row) - -SELECT * FROM pg_stat_monitor_settings WHERE name NOT LIKE 'pg_stat_monitor.pgsm_track_planning' ORDER BY name COLLATE "C"; - name | value | default_value | description | minimum | maximum | options | restart -------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+--------- - pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes - pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no - pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no - pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 50 | | yes - pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes - pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes - pg_stat_monitor.pgsm_max | 100 | 100 | Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor. | 1 | 1000 | | yes - pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes - pg_stat_monitor.pgsm_normalized_query | no | no | Selects whether save query in normalized format. | | | yes, no | no - pg_stat_monitor.pgsm_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes - pg_stat_monitor.pgsm_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes - pg_stat_monitor.pgsm_query_shared_buffer | 20 | 20 | Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor. | 1 | 10000 | | yes - pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no - pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no -(14 rows) - -SELECT pg_stat_monitor_reset(); - pg_stat_monitor_reset ------------------------ - -(1 row) +\x +SELECT name + , setting + , unit + , category + , short_desc + , extra_desc + , context + , vartype + , source + , min_val + , max_val + , enumvals + , boot_val + , reset_val + , sourcefile + , sourceline + , pending_restart +FROM pg_settings +WHERE name LIKE 'pg_stat_monitor.%' + AND name NOT LIKE 'pg_stat_monitor.pgsm_track_planning' +ORDER +BY name +COLLATE "C"; +-[ RECORD 1 ]---+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_bucket_time +setting | 60 +unit | +category | Customized Options +short_desc | Sets the time in seconds per bucket. +extra_desc | +context | postmaster +vartype | integer +source | default +min_val | 1 +max_val | 2147483647 +enumvals | +boot_val | 60 +reset_val | 60 +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 2 ]---+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_enable_query_plan +setting | off +unit | +category | Customized Options +short_desc | Enable/Disable query plan monitoring +extra_desc | +context | user +vartype | bool +source | default +min_val | +max_val | +enumvals | +boot_val | off +reset_val | off +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 3 ]---+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_extract_comments +setting | off +unit | +category | Customized Options +short_desc | Enable/Disable extracting comments from queries. +extra_desc | +context | user +vartype | bool +source | default +min_val | +max_val | +enumvals | +boot_val | off +reset_val | off +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 4 ]---+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_histogram_buckets +setting | 10 +unit | +category | Customized Options +short_desc | Sets the maximum number of histogram buckets +extra_desc | +context | postmaster +vartype | integer +source | default +min_val | 2 +max_val | 50 +enumvals | +boot_val | 10 +reset_val | 10 +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 5 ]---+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_histogram_max +setting | 100000 +unit | +category | Customized Options +short_desc | Sets the time in millisecond. +extra_desc | +context | postmaster +vartype | integer +source | default +min_val | 10 +max_val | 2147483647 +enumvals | +boot_val | 100000 +reset_val | 100000 +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 6 ]---+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_histogram_min +setting | 0 +unit | +category | Customized Options +short_desc | Sets the time in millisecond. +extra_desc | +context | postmaster +vartype | integer +source | default +min_val | 0 +max_val | 2147483647 +enumvals | +boot_val | 0 +reset_val | 0 +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 7 ]---+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_max +setting | 100 +unit | MB +category | Customized Options +short_desc | Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor. +extra_desc | +context | postmaster +vartype | integer +source | default +min_val | 1 +max_val | 1000 +enumvals | +boot_val | 100 +reset_val | 100 +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 8 ]---+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_max_buckets +setting | 10 +unit | +category | Customized Options +short_desc | Sets the maximum number of buckets. +extra_desc | +context | postmaster +vartype | integer +source | default +min_val | 1 +max_val | 10 +enumvals | +boot_val | 10 +reset_val | 10 +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 9 ]---+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_normalized_query +setting | off +unit | +category | Customized Options +short_desc | Selects whether save query in normalized format. +extra_desc | +context | user +vartype | bool +source | default +min_val | +max_val | +enumvals | +boot_val | off +reset_val | off +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 10 ]--+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_overflow_target +setting | 1 +unit | +category | Customized Options +short_desc | Sets the overflow target for pg_stat_monitor +extra_desc | +context | postmaster +vartype | integer +source | default +min_val | 0 +max_val | 1 +enumvals | +boot_val | 1 +reset_val | 1 +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 11 ]--+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_query_max_len +setting | 2048 +unit | +category | Customized Options +short_desc | Sets the maximum length of query. +extra_desc | +context | postmaster +vartype | integer +source | default +min_val | 1024 +max_val | 2147483647 +enumvals | +boot_val | 2048 +reset_val | 2048 +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 12 ]--+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_query_shared_buffer +setting | 20 +unit | MB +category | Customized Options +short_desc | Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor. +extra_desc | +context | postmaster +vartype | integer +source | default +min_val | 1 +max_val | 10000 +enumvals | +boot_val | 20 +reset_val | 20 +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 13 ]--+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_track +setting | top +unit | +category | Customized Options +short_desc | Selects which statements are tracked by pg_stat_monitor. +extra_desc | +context | user +vartype | enum +source | default +min_val | +max_val | +enumvals | {none,top,all} +boot_val | top +reset_val | top +sourcefile | +sourceline | +pending_restart | f +-[ RECORD 14 ]--+--------------------------------------------------------------------------------------------------------- +name | pg_stat_monitor.pgsm_track_utility +setting | on +unit | +category | Customized Options +short_desc | Selects whether utility commands are tracked. +extra_desc | +context | user +vartype | bool +source | default +min_val | +max_val | +enumvals | +boot_val | on +reset_val | on +sourcefile | +sourceline | +pending_restart | f +\x DROP EXTENSION pg_stat_monitor; diff --git a/regression/sql/guc.sql b/regression/sql/guc.sql index ee22e5e..9743b34 100644 --- a/regression/sql/guc.sql +++ b/regression/sql/guc.sql @@ -1,6 +1,31 @@ CREATE EXTENSION pg_stat_monitor; -SELECT pg_stat_monitor_reset(); -select pg_sleep(.5); -SELECT * FROM pg_stat_monitor_settings WHERE name NOT LIKE 'pg_stat_monitor.pgsm_track_planning' ORDER BY name COLLATE "C"; -SELECT pg_stat_monitor_reset(); + +\x + +SELECT name + , setting + , unit + , category + , short_desc + , extra_desc + , context + , vartype + , source + , min_val + , max_val + , enumvals + , boot_val + , reset_val + , sourcefile + , sourceline + , pending_restart +FROM pg_settings +WHERE name LIKE 'pg_stat_monitor.%' + AND name NOT LIKE 'pg_stat_monitor.pgsm_track_planning' +ORDER +BY name +COLLATE "C"; + +\x + DROP EXTENSION pg_stat_monitor;