Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/hash_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ typedef struct pgsmLocalState
dsa_area *dsa; /* local dsa area for backend attached to the
* dsa area created by postmaster at startup. */
HTAB *shared_hash;
MemoryContext pgsm_mem_cxt;
} pgsmLocalState;

static pgsmLocalState pgsmStateLocal;
Expand Down Expand Up @@ -122,9 +121,6 @@ pgsm_startup(void)
LWLockRelease(AddinShmemInitLock);

pgsmStateLocal.shared_pgsmState = pgsm;
pgsmStateLocal.pgsm_mem_cxt = AllocSetContextCreate(TopMemoryContext,
"pg_stat_monitor local store",
ALLOCSET_DEFAULT_SIZES);

/* Reset in case this is a restart within the postmaster */
pgsmStateLocal.dsa = NULL;
Expand Down Expand Up @@ -177,12 +173,6 @@ pgsm_attach_shmem(void)
MemoryContextSwitchTo(oldcontext);
}

MemoryContext
GetPgsmMemoryContext(void)
{
return pgsmStateLocal.pgsm_mem_cxt;
}

dsa_area *
get_dsa_area_for_query_text(void)
{
Expand Down
1 change: 0 additions & 1 deletion src/hash_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ typedef struct pgsmSharedState

/* hash_query.c */
void pgsm_startup(void);
MemoryContext GetPgsmMemoryContext(void);
dsa_area *get_dsa_area_for_query_text(void);
HTAB *get_pgsmHash(void);
bool IsSystemOOM(void);
Expand Down
12 changes: 9 additions & 3 deletions src/pg_stat_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ typedef enum pgsmStoreKind
/*---- Initialization Function Declarations ----*/
void _PG_init(void);

static MemoryContext PgsmMemoryContext;

/* Current nesting depth of planner/ExecutorRun/ProcessUtility calls */
static int nesting_level = 0;
static int max_nesting_level;
Expand Down Expand Up @@ -338,6 +340,10 @@ _PG_init(void)

oldctx = MemoryContextSwitchTo(TopMemoryContext);

PgsmMemoryContext = AllocSetContextCreate(TopMemoryContext,
"pg_stat_monitor local store",
ALLOCSET_DEFAULT_SIZES);

nested_queryids = palloc_array(int64, max_nesting_level);
nested_query_txts = palloc0_array(char *, max_nesting_level);

Expand Down Expand Up @@ -1527,7 +1533,7 @@ static void
pgsm_add_to_list(pgsmEntry *entry, const char *query_text, int query_len)
{
/* Switch to pgsm memory context */
MemoryContext oldctx = MemoryContextSwitchTo(GetPgsmMemoryContext());
MemoryContext oldctx = MemoryContextSwitchTo(PgsmMemoryContext);

entry->query_text.query_pointer = pnstrdup(query_text, query_len);
lentries = lappend(lentries, entry);
Expand Down Expand Up @@ -1614,7 +1620,7 @@ static void
pgsm_cleanup_callback(void *arg)
{
/* Reset the memory context holding the list */
MemoryContextReset(GetPgsmMemoryContext());
MemoryContextReset(PgsmMemoryContext);

lentries = NIL;
callback_setup = false;
Expand All @@ -1631,7 +1637,7 @@ pgsm_create_hash_entry(int64 queryid, const PlanInfo *plan_info)
MemoryContext oldctx;

/* Create an entry in the pgsm memory context */
oldctx = MemoryContextSwitchTo(GetPgsmMemoryContext());
oldctx = MemoryContextSwitchTo(PgsmMemoryContext);
entry = palloc0_object(pgsmEntry);

/*
Expand Down
Loading