Skip to content

Commit

Permalink
Issue (percona#47): Default values of setting are not set properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrarahmad committed Sep 30, 2020
1 parent 680d7a6 commit d66a079
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 45 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ make USE_PGXS=1 install
Here is the complete list of configuration parameters.

```
postgres=# select name,value, minimum, maximum from pg_stat_monitor_settings;
name | value | minimum | maximum
-----------------------------------------------+--------+---------+------------
pg_stat_monitor.pgsm_max | 5000 | 5000 | 2147483647
pg_stat_monitor.pgsm_query_max_len | 1024 | 1024 | 2147483647
pg_stat_monitor.pgsm_enable | 1 | 0 | 0
pg_stat_monitor.pgsm_track_utility | 1 | 0 | 0
pg_stat_monitor.pgsm_normalized_query | 1 | 0 | 0
pg_stat_monitor.pgsm_max_buckets | 10 | 1 | 10
pg_stat_monitor.pgsm_bucket_time | 60 | 1 | 2147483647
pg_stat_monitor.pgsm_object_cache | 500000 | 5 | 10
pg_stat_monitor.pgsm_respose_time_lower_bound | 5 | 1 | 2147483647
pg_stat_monitor.pgsm_respose_time_step | 1 | 1 | 2147483647
pg_stat_monitor.pgsm_query_shared_buffer | 1 | 500000 | 2147483647
postgres=# select * from pg_stat_monitor_settings;
name | value | default_value | description | minimum | maximum | restart
-----------------------------------------------+--------+---------------+-------------------------------------------------------------------+---------+------------+---------
pg_stat_monitor.pgsm_max | 5000 | 5000 | Sets the maximum number of statements tracked by pg_stat_monitor. | 5000 | 2147483647 | 1
pg_stat_monitor.pgsm_query_max_len | 1024 | 1024 | Sets the maximum length of query. | 1024 | 2147483647 | 1
pg_stat_monitor.pgsm_enable | 1 | 1 | Enable/Disable statistics collector. | 0 | 0 | 1
pg_stat_monitor.pgsm_track_utility | 1 | 0 | Selects whether utility commands are tracked. | 0 | 0 | 0
pg_stat_monitor.pgsm_normalized_query | 1 | 0 | Selects whether save query in normalized format. | 0 | 0 | 0
pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | 1
pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | 1
pg_stat_monitor.pgsm_object_cache | 50 | 50 | Sets the maximum number of object cache | 50 | 2147483647 | 1
pg_stat_monitor.pgsm_respose_time_lower_bound | 1 | 1 | Sets the time in millisecond. | 1 | 2147483647 | 1
pg_stat_monitor.pgsm_respose_time_step | 1 | 1 | Sets the respose time steps in millisecond. | 1 | 2147483647 | 1
pg_stat_monitor.pgsm_query_shared_buffer | 500000 | 500000 | Sets the query shared_buffer size. | 500000 | 2147483647 | 1
(11 rows)
```

Expand Down
45 changes: 19 additions & 26 deletions hash_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* hash_query.c
* Track statement execution times across a whole database cluster.
*
* Copyright (c) 2008-2018, PostgreSQL Global Development Group
* Copyright (c) 2008-2020, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pg_stat_monitor/hash_query.c
Expand Down Expand Up @@ -57,8 +57,8 @@ pgss_shmem_startup(void)
pgss_waiteventshash = NULL;

/*
* Create or attach to the shared memory state, including hash table
*/
* Create or attach to the shared memory state, including hash table
*/
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);

pgss = ShmemInitStruct("pg_stat_monitor", sizeof(pgssSharedState), &found);
Expand All @@ -71,28 +71,17 @@ pgss_shmem_startup(void)
}

pgss->query_buf_size_bucket = PGSM_QUERY_BUF_SIZE / PGSM_MAX_BUCKETS;

for (i = 0; i < PGSM_MAX_BUCKETS; i++)
pgss_qbuf[i] = (unsigned char *) ShmemAlloc(pgss->query_buf_size_bucket);

pgss_hash = hash_init("pg_stat_monitor: Queries hashtable",
sizeof(pgssHashKey),
sizeof(pgssEntry),
PGSM_MAX);
pgss_hash = hash_init("pg_stat_monitor: Queries hashtable", sizeof(pgssHashKey), sizeof(pgssEntry),PGSM_MAX);

pgss_buckethash = hash_init("pg_stat_monitor: Bucket hashtable",
sizeof(pgssBucketHashKey),
sizeof(pgssBucketEntry),
PGSM_MAX_BUCKETS);
pgss_buckethash = hash_init("pg_stat_monitor: Bucket hashtable", sizeof(pgssBucketHashKey), sizeof(pgssBucketEntry), PGSM_MAX_BUCKETS);

pgss_waiteventshash = hash_init("pg_stat_monitor: Wait Event hashtable",
sizeof(pgssWaitEventKey),
sizeof(pgssWaitEventEntry),
100);
pgss_waiteventshash = hash_init("pg_stat_monitor: Wait Event hashtable", sizeof(pgssWaitEventKey), sizeof(pgssWaitEventEntry), 100);

pgss_object_hash = hash_init("pg_stat_monitor: Object hashtable",
sizeof(pgssObjectHashKey),
sizeof(pgssObjectEntry),
PGSM_OBJECT_CACHE);
pgss_object_hash = hash_init("pg_stat_monitor: Object hashtable", sizeof(pgssObjectHashKey), sizeof(pgssObjectEntry), PGSM_OBJECT_CACHE);

Assert(IsHashInitialize());

Expand Down Expand Up @@ -133,17 +122,16 @@ pgss_shmem_startup(void)
LWLockRelease(AddinShmemInitLock);

/*
* If we're in the postmaster (or a standalone backend...), set up a shmem
* exit hook to dump the statistics to disk.
*/
* If we're in the postmaster (or a standalone backend...), set up a shmem
* exit hook to dump the statistics to disk.
*/
if (!IsUnderPostmaster)
on_shmem_exit(pgss_shmem_shutdown, (Datum) 0);
}

int
pgsm_get_bucket_size(void)
{
Assert(pgss->query_buf_size_bucket <= 0);
return pgss->query_buf_size_bucket;
}

Expand All @@ -155,26 +143,31 @@ pgssSharedState* pgsm_get_ss(void)

HTAB* pgsm_get_hash(void)
{
Assert(pgss_hash);
return pgss_hash;
}

pgssBucketEntry** pgsm_get_bucket_entries(void)
{
Assert(pgssBucketEntries);
return pgssBucketEntries;
}

HTAB* pgsm_get_wait_event_hash(void)
{
Assert(pgss_waiteventshash);
return pgss_waiteventshash;
}

pgssBucketEntry** pgsm_get_bucket(void)
{
Assert(pgssBucketEntries);
return pgssBucketEntries;
}

pgssWaitEventEntry** pgsm_get_wait_event_entry(void)
{
Assert(pgssWaitEventEntries);
return pgssWaitEventEntries;
}

Expand Down Expand Up @@ -308,7 +301,7 @@ hash_entry_reset()
}

void
add_object_entry(uint64 queryid, char *objects)
hash_alloc_object_entry(uint64 queryid, char *objects)
{
pgssObjectEntry *entry = NULL;
bool found;
Expand All @@ -328,7 +321,7 @@ add_object_entry(uint64 queryid, char *objects)

/* De-alocate memory */
void
remove_object_entry(uint64 queryid, char *objects)
hash_dealloc_object_entry(uint64 queryid, char *objects)
{
pgssObjectHashKey key;
pgssObjectEntry *entry;
Expand All @@ -346,7 +339,7 @@ remove_object_entry(uint64 queryid, char *objects)
}

pgssEntry*
pgsm_create_query_entry(unsigned int queryid,
hash_create_query_entry(unsigned int queryid,
unsigned int userid,
unsigned int dbid,
unsigned int bucket_id,
Expand Down
4 changes: 2 additions & 2 deletions pg_stat_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ pgss_post_parse_analyze(ParseState *pstate, Query *query)
}
}
}
add_object_entry(query->queryId, tables_name);
hash_alloc_object_entry(query->queryId, tables_name);
}

/*
Expand Down Expand Up @@ -711,7 +711,7 @@ static void pgss_store(const char *query, uint64 queryId,
if (queryId == UINT64CONST(0))
queryId = pgss_hash_string(query, query_len);

remove_object_entry(queryId, tables_name);
hash_dealloc_object_entry(queryId, tables_name);
len = strlen(tables_name);

/* Set up key for hashtable search */
Expand Down
6 changes: 3 additions & 3 deletions pg_stat_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ typedef struct pgssJumbleState
void init_guc(void);

/* hash_create.c */
void add_object_entry(uint64 queryid, char *objects);
void remove_object_entry(uint64 queryid, char *objects);
void hash_alloc_object_entry(uint64 queryid, char *objects);
void hash_dealloc_object_entry(uint64 queryid, char *objects);
bool IsHashInitialize(void);
void pgss_shmem_startup(void);
void pgss_shmem_shutdown(int code, Datum arg);
Expand All @@ -327,7 +327,7 @@ void hash_entry_reset(void);
void hash_entry_dealloc(int bucket);
pgssEntry* hash_entry_alloc(pgssSharedState *pgss, pgssHashKey *key, int encoding);
Size hash_memsize(void);
pgssEntry* pgsm_create_query_entry(unsigned int queryid, unsigned int userid, unsigned int dbid, unsigned int bucket_id, unsigned int ip);
pgssEntry* hash_create_query_entry(unsigned int queryid, unsigned int userid, unsigned int dbid, unsigned int bucket_id, unsigned int ip);

/*---- GUC variables ----*/
#define PGSM_MAX conf[0].guc_variable
Expand Down

0 comments on commit d66a079

Please sign in to comment.