mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +03:00
Introduce pg_dsm_registry_allocations view.
This commit adds a new system view that provides information about entries in the dynamic shared memory (DSM) registry. Specifically, it returns the name, type, and size of each entry. Note that since we cannot discover the size of dynamic shared memory areas (DSAs) and hash tables backed by DSAs (dshashes) without first attaching to them, the size column is left as NULL for those. Bumps catversion. Author: Florents Tselai <florents.tselai@gmail.com> Reviewed-by: Sungwoo Chang <swchangdev@gmail.com> Discussion: https://postgr.es/m/4D445D3E-81C5-4135-95BB-D414204A0AB4%40gmail.com
This commit is contained in:
@@ -40,10 +40,12 @@
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "funcapi.h"
|
||||
#include "lib/dshash.h"
|
||||
#include "storage/dsm_registry.h"
|
||||
#include "storage/lwlock.h"
|
||||
#include "storage/shmem.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/memutils.h"
|
||||
|
||||
#define DSMR_NAME_LEN 128
|
||||
@@ -88,6 +90,13 @@ typedef enum DSMREntryType
|
||||
DSMR_ENTRY_TYPE_DSH,
|
||||
} DSMREntryType;
|
||||
|
||||
static const char *const DSMREntryTypeNames[] =
|
||||
{
|
||||
[DSMR_ENTRY_TYPE_DSM] = "segment",
|
||||
[DSMR_ENTRY_TYPE_DSA] = "area",
|
||||
[DSMR_ENTRY_TYPE_DSH] = "hash",
|
||||
};
|
||||
|
||||
typedef struct DSMRegistryEntry
|
||||
{
|
||||
char name[DSMR_NAME_LEN];
|
||||
@@ -435,3 +444,43 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_get_dsm_registry_allocations(PG_FUNCTION_ARGS)
|
||||
{
|
||||
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
|
||||
DSMRegistryEntry *entry;
|
||||
MemoryContext oldcontext;
|
||||
dshash_seq_status status;
|
||||
|
||||
InitMaterializedSRF(fcinfo, MAT_SRF_USE_EXPECTED_DESC);
|
||||
|
||||
/* Be sure any local memory allocated by DSM/DSA routines is persistent. */
|
||||
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
|
||||
init_dsm_registry();
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
|
||||
dshash_seq_init(&status, dsm_registry_table, false);
|
||||
while ((entry = dshash_seq_next(&status)) != NULL)
|
||||
{
|
||||
Datum vals[3];
|
||||
bool nulls[3] = {0};
|
||||
|
||||
vals[0] = CStringGetTextDatum(entry->name);
|
||||
vals[1] = CStringGetTextDatum(DSMREntryTypeNames[entry->type]);
|
||||
|
||||
/*
|
||||
* Since we can't know the size of DSA/dshash entries without first
|
||||
* attaching to them, return NULL for those.
|
||||
*/
|
||||
if (entry->type == DSMR_ENTRY_TYPE_DSM)
|
||||
vals[2] = Int64GetDatum(entry->data.dsm.size);
|
||||
else
|
||||
nulls[2] = true;
|
||||
|
||||
tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, vals, nulls);
|
||||
}
|
||||
dshash_seq_term(&status);
|
||||
|
||||
return (Datum) 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user