Merge pull request #334 from EngineeredVirus/main

PG-354: pg_stat_monitor: Remove pg_stat_monitor_settings view
This commit is contained in:
Ibrar Ahmed
2022-12-21 20:34:00 +05:00
committed by GitHub
5 changed files with 307 additions and 198 deletions

View File

@@ -123,7 +123,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);
@@ -3115,136 +3114,6 @@ intarray_get_datum(int32 arr[], int len)
}
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)
{