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
Ibrar Ahmed 2020-10-12 19:41:48 +00:00
parent b23df84af9
commit 166ee0a25b
2 changed files with 5 additions and 11 deletions

View File

@ -248,24 +248,15 @@ hash_entry_dealloc(int bucket)
{
HASH_SEQ_STATUS hash_seq;
pgssEntry *entry;
pgssEntry **entries;
int i;
int nvictims = 0;
pgss->bucket_entry[bucket] = 0;
entries = palloc(hash_get_num_entries(pgss_hash) * sizeof(pgssEntry *));
hash_seq_init(&hash_seq, pgss_hash);
while ((entry = hash_seq_search(&hash_seq)) != NULL)
{
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;
LWLockAcquire(pgss->lock, LW_SHARED);
LWLockAcquire(pgss->lock, LW_EXCLUSIVE);
entry = (pgssObjectEntry *) hash_search(pgss_object_hash, &key, HASH_FIND, NULL);
if (entry != NULL)
{

View File

@ -875,12 +875,15 @@ exit:
Datum
pg_stat_monitor_reset(PG_FUNCTION_ARGS)
{
pgssSharedState *pgss = pgsm_get_ss();
/* Safety check... */
if (!IsHashInitialize())
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("pg_stat_monitor: must be loaded via shared_preload_libraries")));
LWLockAcquire(pgss->lock, LW_EXCLUSIVE);
hash_entry_dealloc(-1);
LWLockRelease(pgss->lock);
PG_RETURN_VOID();
}