Issue - (#51): Postgres process is taking too much CPU.
Jira: PG-141 There is lock conflict, so used LW_EXCLUSIVE instead of LW_SHARED. This need to be investigated again and check the possibility to use a shared lock.pull/55/head
parent
b23df84af9
commit
166ee0a25b
13
hash_query.c
13
hash_query.c
|
@ -248,24 +248,15 @@ hash_entry_dealloc(int bucket)
|
||||||
{
|
{
|
||||||
HASH_SEQ_STATUS hash_seq;
|
HASH_SEQ_STATUS hash_seq;
|
||||||
pgssEntry *entry;
|
pgssEntry *entry;
|
||||||
pgssEntry **entries;
|
|
||||||
int i;
|
|
||||||
int nvictims = 0;
|
|
||||||
|
|
||||||
pgss->bucket_entry[bucket] = 0;
|
pgss->bucket_entry[bucket] = 0;
|
||||||
|
|
||||||
entries = palloc(hash_get_num_entries(pgss_hash) * sizeof(pgssEntry *));
|
|
||||||
hash_seq_init(&hash_seq, pgss_hash);
|
hash_seq_init(&hash_seq, pgss_hash);
|
||||||
while ((entry = hash_seq_search(&hash_seq)) != NULL)
|
while ((entry = hash_seq_search(&hash_seq)) != NULL)
|
||||||
{
|
{
|
||||||
if (entry->key.bucket_id == bucket || bucket < 0)
|
if (entry->key.bucket_id == bucket || bucket < 0)
|
||||||
entries[nvictims++] = entry;
|
entry = hash_search(pgss_hash, &entry->key, HASH_REMOVE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nvictims; i++)
|
|
||||||
entry = hash_search(pgss_hash, &entries[i]->key, HASH_REMOVE, NULL);
|
|
||||||
|
|
||||||
pfree(entries);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -332,7 +323,7 @@ hash_dealloc_object_entry(uint64 queryid, char *objects)
|
||||||
|
|
||||||
key.queryid = queryid;
|
key.queryid = queryid;
|
||||||
|
|
||||||
LWLockAcquire(pgss->lock, LW_SHARED);
|
LWLockAcquire(pgss->lock, LW_EXCLUSIVE);
|
||||||
entry = (pgssObjectEntry *) hash_search(pgss_object_hash, &key, HASH_FIND, NULL);
|
entry = (pgssObjectEntry *) hash_search(pgss_object_hash, &key, HASH_FIND, NULL);
|
||||||
if (entry != NULL)
|
if (entry != NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -875,12 +875,15 @@ exit:
|
||||||
Datum
|
Datum
|
||||||
pg_stat_monitor_reset(PG_FUNCTION_ARGS)
|
pg_stat_monitor_reset(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
|
pgssSharedState *pgss = pgsm_get_ss();
|
||||||
/* Safety check... */
|
/* Safety check... */
|
||||||
if (!IsHashInitialize())
|
if (!IsHashInitialize())
|
||||||
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")));
|
||||||
|
LWLockAcquire(pgss->lock, LW_EXCLUSIVE);
|
||||||
hash_entry_dealloc(-1);
|
hash_entry_dealloc(-1);
|
||||||
|
LWLockRelease(pgss->lock);
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue