PG-579: Querying pg_stat_monitor crashes the server ... (#351)
pgsm_get_ss() must only be called when pg_stat_monitor.so is loaded. Fix is to move the pgsm_get_ss() call after checking if the pg_stat_monotor library is loaded or not.pull/354/head
parent
2c5e12af0a
commit
caeb5f5e73
|
@ -1411,7 +1411,7 @@ pgss_store(uint64 queryid,
|
||||||
{
|
{
|
||||||
pgssHashKey key;
|
pgssHashKey key;
|
||||||
pgssEntry *entry;
|
pgssEntry *entry;
|
||||||
pgssSharedState *pgss = pgsm_get_ss();
|
pgssSharedState *pgss;
|
||||||
char *app_name_ptr;
|
char *app_name_ptr;
|
||||||
char app_name[APPLICATIONNAME_LEN] = "";
|
char app_name[APPLICATIONNAME_LEN] = "";
|
||||||
int app_name_len = 0;
|
int app_name_len = 0;
|
||||||
|
@ -1434,6 +1434,8 @@ pgss_store(uint64 queryid,
|
||||||
if (!IsSystemInitialized())
|
if (!IsSystemInitialized())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
pgss = pgsm_get_ss();
|
||||||
|
|
||||||
#if PG_VERSION_NUM >= 140000
|
#if PG_VERSION_NUM >= 140000
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1652,13 +1654,15 @@ pgss_store(uint64 queryid,
|
||||||
Datum
|
Datum
|
||||||
pg_stat_monitor_reset(PG_FUNCTION_ARGS)
|
pg_stat_monitor_reset(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
pgssSharedState *pgss = pgsm_get_ss();
|
pgssSharedState *pgss;
|
||||||
|
|
||||||
/* Safety check... */
|
/* Safety check... */
|
||||||
if (!IsSystemInitialized())
|
if (!IsSystemInitialized())
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||||
errmsg("pg_stat_monitor: must be loaded via shared_preload_libraries")));
|
errmsg("pg_stat_monitor: must be loaded via shared_preload_libraries")));
|
||||||
|
|
||||||
|
pgss = pgsm_get_ss();
|
||||||
LWLockAcquire(pgss->lock, LW_EXCLUSIVE);
|
LWLockAcquire(pgss->lock, LW_EXCLUSIVE);
|
||||||
hash_entry_dealloc(-1, -1, NULL);
|
hash_entry_dealloc(-1, -1, NULL);
|
||||||
|
|
||||||
|
@ -1721,7 +1725,7 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
|
||||||
PGSM_HASH_SEQ_STATUS hstat;
|
PGSM_HASH_SEQ_STATUS hstat;
|
||||||
pgssEntry *entry;
|
pgssEntry *entry;
|
||||||
char parentid_txt[32];
|
char parentid_txt[32];
|
||||||
pgssSharedState *pgss = pgsm_get_ss();
|
pgssSharedState *pgss;
|
||||||
char *query_txt = NULL;
|
char *query_txt = NULL;
|
||||||
char *parent_query_txt = NULL;
|
char *parent_query_txt = NULL;
|
||||||
int expected_columns = (api_version >= PGSM_V2_0)?PG_STAT_MONITOR_COLS_V2_0:PG_STAT_MONITOR_COLS_V1_0;
|
int expected_columns = (api_version >= PGSM_V2_0)?PG_STAT_MONITOR_COLS_V2_0:PG_STAT_MONITOR_COLS_V1_0;
|
||||||
|
@ -1743,6 +1747,8 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
|
||||||
errmsg("pg_stat_monitor: materialize mode required, but it is not " \
|
errmsg("pg_stat_monitor: materialize mode required, but it is not " \
|
||||||
"allowed in this context")));
|
"allowed in this context")));
|
||||||
|
|
||||||
|
pgss = pgsm_get_ss();
|
||||||
|
|
||||||
/* Switch into long-lived context to construct returned data structures */
|
/* Switch into long-lived context to construct returned data structures */
|
||||||
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
|
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
|
||||||
oldcontext = MemoryContextSwitchTo(per_query_ctx);
|
oldcontext = MemoryContextSwitchTo(per_query_ctx);
|
||||||
|
|
Loading…
Reference in New Issue