mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
Add system view pg_wait_events
This new view, wrapped around a SRF, shows some information known about wait events, as of: - Name. - Type (Activity, I/O, Extension, etc.). - Description. All the information retrieved comes from wait_event_names.txt, and the description is the same as the documentation with filters applied to remove any XML markups. This view is useful when joined with pg_stat_activity to get the description of a wait event reported. Custom wait events for extensions are included in the view. Original idea by Yves Colin. Author: Bertrand Drouvot Reviewed-by: Kyotaro Horiguchi, Masahiro Ikeda, Tom Lane, Michael Paquier Discussion: https://postgr.es/m/0e2ae164-dc89-03c3-cf7f-de86378053ac@gmail.com
This commit is contained in:
93
src/backend/utils/activity/wait_event_funcs.c
Normal file
93
src/backend/utils/activity/wait_event_funcs.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/*------------------------------------------------------------------------
|
||||
*
|
||||
* wait_event_funcs.c
|
||||
* Functions for accessing wait event data.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* src/backend/utils/activity/wait_event_funcs.c
|
||||
*
|
||||
*------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include "funcapi.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/wait_event.h"
|
||||
|
||||
/*
|
||||
* Each wait event has one corresponding entry in this structure, fed to
|
||||
* the SQL function of this file.
|
||||
*/
|
||||
static const struct
|
||||
{
|
||||
const char *type;
|
||||
const char *name;
|
||||
const char *description;
|
||||
}
|
||||
|
||||
waitEventData[] =
|
||||
{
|
||||
#include "wait_event_funcs_data.c"
|
||||
/* end of list */
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* pg_get_wait_events
|
||||
*
|
||||
* List information about wait events (type, name and description).
|
||||
*/
|
||||
Datum
|
||||
pg_get_wait_events(PG_FUNCTION_ARGS)
|
||||
{
|
||||
#define PG_GET_WAIT_EVENTS_COLS 3
|
||||
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
|
||||
char **waiteventnames;
|
||||
int nbextwaitevents;
|
||||
|
||||
/* Build tuplestore to hold the result rows */
|
||||
InitMaterializedSRF(fcinfo, 0);
|
||||
|
||||
/* Iterate over the list of wait events */
|
||||
for (int idx = 0; waitEventData[idx].type != NULL; idx++)
|
||||
{
|
||||
Datum values[PG_GET_WAIT_EVENTS_COLS] = {0};
|
||||
bool nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
|
||||
|
||||
values[0] = CStringGetTextDatum(waitEventData[idx].type);
|
||||
values[1] = CStringGetTextDatum(waitEventData[idx].name);
|
||||
values[2] = CStringGetTextDatum(waitEventData[idx].description);
|
||||
|
||||
tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
|
||||
}
|
||||
|
||||
/* Handle custom wait events for extensions */
|
||||
waiteventnames = GetWaitEventExtensionNames(&nbextwaitevents);
|
||||
|
||||
for (int idx = 0; idx < nbextwaitevents; idx++)
|
||||
{
|
||||
StringInfoData buf;
|
||||
Datum values[PG_GET_WAIT_EVENTS_COLS] = {0};
|
||||
bool nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
|
||||
|
||||
|
||||
values[0] = CStringGetTextDatum("Extension");
|
||||
values[1] = CStringGetTextDatum(waiteventnames[idx]);
|
||||
|
||||
initStringInfo(&buf);
|
||||
appendStringInfo(&buf,
|
||||
"Waiting for custom wait event \"%s\" defined by extension module",
|
||||
waiteventnames[idx]);
|
||||
|
||||
values[2] = CStringGetTextDatum(buf.data);
|
||||
|
||||
tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
|
||||
}
|
||||
|
||||
return (Datum) 0;
|
||||
}
|
||||
Reference in New Issue
Block a user