PG-543: pg_stat_monitor: PostgreSQL's pg_stat_statements compatible view. (#352)

* PG-543: pg_stat_monitor: PostgreSQL's pg_stat_statements compatible view.

The view now carries all the columns as pg_stat_statements. This required fixing
data types of some of the columns, renaming a few, as well inclusion of new
columns to make the view fully compatible with pg_stat_statements.

* PG-543: pg_stat_monitor: PostgreSQL's pg_stat_statements compatible view.

Updating the upgrade sql file from 1.0 to 2.0 version linked with this issue
changes.

* PG-543: pg_stat_monitor: PostgreSQL's pg_stat_statements compatible view.

Updating datum calls to use UInt64 rather than Int64.
This commit is contained in:
Hamid Akhtar
2023-01-19 01:55:20 +05:00
committed by GitHub
parent 7dece7cf1d
commit 1286427445
7 changed files with 91 additions and 81 deletions

View File

@@ -1722,7 +1722,6 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
MemoryContext oldcontext;
PGSM_HASH_SEQ_STATUS hstat;
pgssEntry *entry;
char parentid_txt[32];
pgssSharedState *pgss;
char *query_txt = NULL;
char *parent_query_txt = NULL;
@@ -1776,15 +1775,13 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
int i = 0;
Counters tmp;
double stddev;
char queryid_text[32] = {0};
char planid_text[32] = {0};
uint64 queryid = entry->key.queryid;
int64 bucketid = entry->key.bucket_id;
uint64 dbid = entry->key.dbid;
uint64 userid = entry->key.userid;
int64 ip = entry->key.ip;
uint64 planid = entry->key.planid;
uint64 pgsm_query_id = entry->pgsm_query_id;
uint64 pgsm_query_id = entry->pgsm_query_id;
dsa_area *query_dsa_area;
char *query_ptr;
#if PG_VERSION_NUM < 140000
@@ -1861,14 +1858,12 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
nulls[i++] = true;
/* queryid at column number 4 */
snprintf(queryid_text, 32, "%08lX", queryid);
values[i++] = CStringGetTextDatum(queryid_text);
values[i++] = UInt64GetDatum(queryid);
/* planid at column number 5 */
if (planid)
{
snprintf(planid_text, 32, "%08lX", planid);
values[i++] = CStringGetTextDatum(planid_text);
values[i++] = UInt64GetDatum(planid);
}
else
{
@@ -1906,7 +1901,7 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
values[i++] = CStringGetTextDatum("<insufficient privilege>");
}
values[i++] = Int64GetDatumFast(pgsm_query_id);
values[i++] = UInt64GetDatum(pgsm_query_id);
/* state at column number 8 for V1.0 API*/
if (api_version <= PGSM_V1_0)
@@ -1915,8 +1910,7 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
/* parentid at column number 9 */
if (tmp.info.parentid != UINT64CONST(0))
{
snprintf(parentid_txt, 32, "%08lX", tmp.info.parentid);
values[i++] = CStringGetTextDatum(parentid_txt);
values[i++] = UInt64GetDatum(tmp.info.parentid);
values[i++] = CStringGetTextDatum(parent_query_txt);
}
else