PG-456: Running pgindent to make source PostgreSQL compatible. (#269)

PG-456: Running pgindent to make source indentation/spacing PostgreSQLCompatible.

PostgreSQL uses pgindent from time to time to make source code PostgreSQL
style guide compatible, it is a very long time since we have not done that.
Commit fixes a lot of indentation and spacing issues.

Co-authored-by: Hamid Akhtar <hamid.akhtar@gmail.com>
pull/276/head
Ibrar Ahmed 2022-06-29 00:42:40 +05:00 committed by GitHub
parent 926eade1eb
commit a9187117f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1287 additions and 1151 deletions

78
guc.c
View File

@ -19,10 +19,10 @@
#include "pg_stat_monitor.h" #include "pg_stat_monitor.h"
GucVariable conf[MAX_SETTINGS]; GucVariable conf[MAX_SETTINGS];
static void DefineIntGUC(GucVariable *conf); static void DefineIntGUC(GucVariable * conf);
static void DefineIntGUCWithCheck(GucVariable *conf, GucIntCheckHook check); static void DefineIntGUCWithCheck(GucVariable * conf, GucIntCheckHook check);
static void DefineBoolGUC(GucVariable *conf); static void DefineBoolGUC(GucVariable * conf);
static void DefineEnumGUC(GucVariable *conf, const struct config_enum_entry *options); static void DefineEnumGUC(GucVariable * conf, const struct config_enum_entry *options);
/* Check hooks to ensure histogram_min < histogram_max */ /* Check hooks to ensure histogram_min < histogram_max */
static bool check_histogram_min(int *newval, void **extra, GucSource source); static bool check_histogram_min(int *newval, void **extra, GucSource source);
@ -34,9 +34,11 @@ static bool check_histogram_max(int *newval, void **extra, GucSource source);
void void
init_guc(void) init_guc(void)
{ {
int i = 0, j; int i = 0,
j;
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_max", .guc_name = "pg_stat_monitor.pgsm_max",
.guc_desc = "Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor.", .guc_desc = "Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor.",
.guc_default = 100, .guc_default = 100,
@ -48,7 +50,8 @@ init_guc(void)
}; };
DefineIntGUC(&conf[i++]); DefineIntGUC(&conf[i++]);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_query_max_len", .guc_name = "pg_stat_monitor.pgsm_query_max_len",
.guc_desc = "Sets the maximum length of query.", .guc_desc = "Sets the maximum length of query.",
.guc_default = 2048, .guc_default = 2048,
@ -60,7 +63,8 @@ init_guc(void)
}; };
DefineIntGUC(&conf[i++]); DefineIntGUC(&conf[i++]);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_track_utility", .guc_name = "pg_stat_monitor.pgsm_track_utility",
.guc_desc = "Selects whether utility commands are tracked.", .guc_desc = "Selects whether utility commands are tracked.",
.guc_default = 1, .guc_default = 1,
@ -72,7 +76,8 @@ init_guc(void)
}; };
DefineBoolGUC(&conf[i++]); DefineBoolGUC(&conf[i++]);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_normalized_query", .guc_name = "pg_stat_monitor.pgsm_normalized_query",
.guc_desc = "Selects whether save query in normalized format.", .guc_desc = "Selects whether save query in normalized format.",
.guc_default = 0, .guc_default = 0,
@ -84,7 +89,8 @@ init_guc(void)
}; };
DefineBoolGUC(&conf[i++]); DefineBoolGUC(&conf[i++]);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_max_buckets", .guc_name = "pg_stat_monitor.pgsm_max_buckets",
.guc_desc = "Sets the maximum number of buckets.", .guc_desc = "Sets the maximum number of buckets.",
.guc_default = 10, .guc_default = 10,
@ -96,7 +102,8 @@ init_guc(void)
}; };
DefineIntGUC(&conf[i++]); DefineIntGUC(&conf[i++]);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_bucket_time", .guc_name = "pg_stat_monitor.pgsm_bucket_time",
.guc_desc = "Sets the time in seconds per bucket.", .guc_desc = "Sets the time in seconds per bucket.",
.guc_default = 60, .guc_default = 60,
@ -108,7 +115,8 @@ init_guc(void)
}; };
DefineIntGUC(&conf[i++]); DefineIntGUC(&conf[i++]);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_histogram_min", .guc_name = "pg_stat_monitor.pgsm_histogram_min",
.guc_desc = "Sets the time in millisecond.", .guc_desc = "Sets the time in millisecond.",
.guc_default = 0, .guc_default = 0,
@ -120,7 +128,8 @@ init_guc(void)
}; };
DefineIntGUCWithCheck(&conf[i++], check_histogram_min); DefineIntGUCWithCheck(&conf[i++], check_histogram_min);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_histogram_max", .guc_name = "pg_stat_monitor.pgsm_histogram_max",
.guc_desc = "Sets the time in millisecond.", .guc_desc = "Sets the time in millisecond.",
.guc_default = 100000, .guc_default = 100000,
@ -132,7 +141,8 @@ init_guc(void)
}; };
DefineIntGUCWithCheck(&conf[i++], check_histogram_max); DefineIntGUCWithCheck(&conf[i++], check_histogram_max);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_histogram_buckets", .guc_name = "pg_stat_monitor.pgsm_histogram_buckets",
.guc_desc = "Sets the maximum number of histogram buckets", .guc_desc = "Sets the maximum number of histogram buckets",
.guc_default = 10, .guc_default = 10,
@ -144,7 +154,8 @@ init_guc(void)
}; };
DefineIntGUC(&conf[i++]); DefineIntGUC(&conf[i++]);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_query_shared_buffer", .guc_name = "pg_stat_monitor.pgsm_query_shared_buffer",
.guc_desc = "Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor.", .guc_desc = "Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor.",
.guc_default = 20, .guc_default = 20,
@ -156,7 +167,8 @@ init_guc(void)
}; };
DefineIntGUC(&conf[i++]); DefineIntGUC(&conf[i++]);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_overflow_target", .guc_name = "pg_stat_monitor.pgsm_overflow_target",
.guc_desc = "Sets the overflow target for pg_stat_monitor", .guc_desc = "Sets the overflow target for pg_stat_monitor",
.guc_default = 1, .guc_default = 1,
@ -168,7 +180,8 @@ init_guc(void)
}; };
DefineIntGUC(&conf[i++]); DefineIntGUC(&conf[i++]);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_enable_query_plan", .guc_name = "pg_stat_monitor.pgsm_enable_query_plan",
.guc_desc = "Enable/Disable query plan monitoring", .guc_desc = "Enable/Disable query plan monitoring",
.guc_default = 0, .guc_default = 0,
@ -180,7 +193,8 @@ init_guc(void)
}; };
DefineBoolGUC(&conf[i++]); DefineBoolGUC(&conf[i++]);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_track", .guc_name = "pg_stat_monitor.pgsm_track",
.guc_desc = "Selects which statements are tracked by pg_stat_monitor.", .guc_desc = "Selects which statements are tracked by pg_stat_monitor.",
.n_options = 3, .n_options = 3,
@ -191,12 +205,14 @@ init_guc(void)
.guc_unit = 0, .guc_unit = 0,
.guc_value = &PGSM_TRACK .guc_value = &PGSM_TRACK
}; };
for (j = 0; j < conf[i].n_options; ++j) { for (j = 0; j < conf[i].n_options; ++j)
{
strlcpy(conf[i].guc_options[j], track_options[j].name, sizeof(conf[i].guc_options[j])); strlcpy(conf[i].guc_options[j], track_options[j].name, sizeof(conf[i].guc_options[j]));
} }
DefineEnumGUC(&conf[i++], track_options); DefineEnumGUC(&conf[i++], track_options);
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_extract_comments", .guc_name = "pg_stat_monitor.pgsm_extract_comments",
.guc_desc = "Enable/Disable extracting comments from queries.", .guc_desc = "Enable/Disable extracting comments from queries.",
.guc_default = 0, .guc_default = 0,
@ -209,7 +225,8 @@ init_guc(void)
DefineBoolGUC(&conf[i++]); DefineBoolGUC(&conf[i++]);
#if PG_VERSION_NUM >= 130000 #if PG_VERSION_NUM >= 130000
conf[i] = (GucVariable) { conf[i] = (GucVariable)
{
.guc_name = "pg_stat_monitor.pgsm_track_planning", .guc_name = "pg_stat_monitor.pgsm_track_planning",
.guc_desc = "Selects whether planning statistics are tracked.", .guc_desc = "Selects whether planning statistics are tracked.",
.guc_default = 0, .guc_default = 0,
@ -223,7 +240,8 @@ init_guc(void)
#endif #endif
} }
static void DefineIntGUCWithCheck(GucVariable *conf, GucIntCheckHook check) static void
DefineIntGUCWithCheck(GucVariable * conf, GucIntCheckHook check)
{ {
conf->type = PGC_INT; conf->type = PGC_INT;
DefineCustomIntVariable(conf->guc_name, DefineCustomIntVariable(conf->guc_name,
@ -241,19 +259,19 @@ static void DefineIntGUCWithCheck(GucVariable *conf, GucIntCheckHook check)
} }
static void static void
DefineIntGUC(GucVariable *conf) DefineIntGUC(GucVariable * conf)
{ {
DefineIntGUCWithCheck(conf, NULL); DefineIntGUCWithCheck(conf, NULL);
} }
static void static void
DefineBoolGUC(GucVariable *conf) DefineBoolGUC(GucVariable * conf)
{ {
conf->type = PGC_BOOL; conf->type = PGC_BOOL;
DefineCustomBoolVariable(conf->guc_name, DefineCustomBoolVariable(conf->guc_name,
conf->guc_desc, conf->guc_desc,
NULL, NULL,
(bool*)conf->guc_value, (bool *) conf->guc_value,
conf->guc_default, conf->guc_default,
conf->guc_restart ? PGC_POSTMASTER : PGC_USERSET, conf->guc_restart ? PGC_POSTMASTER : PGC_USERSET,
0, 0,
@ -263,7 +281,7 @@ DefineBoolGUC(GucVariable *conf)
} }
static void static void
DefineEnumGUC(GucVariable *conf, const struct config_enum_entry *options) DefineEnumGUC(GucVariable * conf, const struct config_enum_entry *options)
{ {
conf->type = PGC_ENUM; conf->type = PGC_ENUM;
DefineCustomEnumVariable(conf->guc_name, DefineCustomEnumVariable(conf->guc_name,
@ -279,13 +297,14 @@ DefineEnumGUC(GucVariable *conf, const struct config_enum_entry *options)
NULL); NULL);
} }
GucVariable* GucVariable *
get_conf(int i) get_conf(int i)
{ {
return &conf[i]; return &conf[i];
} }
static bool check_histogram_min(int *newval, void **extra, GucSource source) static bool
check_histogram_min(int *newval, void **extra, GucSource source)
{ {
/* /*
* During module initialization PGSM_HISTOGRAM_MIN is initialized before * During module initialization PGSM_HISTOGRAM_MIN is initialized before
@ -294,7 +313,8 @@ static bool check_histogram_min(int *newval, void **extra, GucSource source)
return (PGSM_HISTOGRAM_MAX == 0 || *newval < PGSM_HISTOGRAM_MAX); return (PGSM_HISTOGRAM_MAX == 0 || *newval < PGSM_HISTOGRAM_MAX);
} }
static bool check_histogram_max(int *newval, void **extra, GucSource source) static bool
check_histogram_max(int *newval, void **extra, GucSource source)
{ {
return (*newval > PGSM_HISTOGRAM_MIN); return (*newval > PGSM_HISTOGRAM_MIN);
} }

View File

@ -25,10 +25,11 @@ static HTAB *pgss_hash;
static HTAB *pgss_query_hash; static HTAB *pgss_query_hash;
static HTAB* static HTAB *
hash_init(const char *hash_name, int key_size, int entry_size, int hash_size) hash_init(const char *hash_name, int key_size, int entry_size, int hash_size)
{ {
HASHCTL info; HASHCTL info;
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
info.keysize = key_size; info.keysize = key_size;
info.entrysize = entry_size; info.entrysize = entry_size;
@ -63,7 +64,7 @@ pgss_startup(void)
init_hook_stats(); init_hook_stats();
#endif #endif
set_qbuf((unsigned char *)ShmemAlloc(MAX_QUERY_BUF)); set_qbuf((unsigned char *) ShmemAlloc(MAX_QUERY_BUF));
pgss_hash = hash_init("pg_stat_monitor: bucket hashtable", sizeof(pgssHashKey), sizeof(pgssEntry), MAX_BUCKET_ENTRIES); pgss_hash = hash_init("pg_stat_monitor: bucket hashtable", sizeof(pgssHashKey), sizeof(pgssEntry), MAX_BUCKET_ENTRIES);
pgss_query_hash = hash_init("pg_stat_monitor: queryID hashtable", sizeof(uint64), sizeof(pgssQueryEntry), MAX_BUCKET_ENTRIES); pgss_query_hash = hash_init("pg_stat_monitor: queryID hashtable", sizeof(uint64), sizeof(pgssQueryEntry), MAX_BUCKET_ENTRIES);
@ -77,19 +78,19 @@ pgss_startup(void)
on_shmem_exit(pgss_shmem_shutdown, (Datum) 0); on_shmem_exit(pgss_shmem_shutdown, (Datum) 0);
} }
pgssSharedState* pgssSharedState *
pgsm_get_ss(void) pgsm_get_ss(void)
{ {
return pgss; return pgss;
} }
HTAB* HTAB *
pgsm_get_hash(void) pgsm_get_hash(void)
{ {
return pgss_hash; return pgss_hash;
} }
HTAB* HTAB *
pgsm_get_query_hash(void) pgsm_get_query_hash(void)
{ {
return pgss_query_hash; return pgss_query_hash;
@ -185,15 +186,19 @@ hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_bu
while ((entry = hash_seq_search(&hash_seq)) != NULL) while ((entry = hash_seq_search(&hash_seq)) != NULL)
{ {
/* /*
* Remove all entries if new_bucket_id == -1. * Remove all entries if new_bucket_id == -1. Otherwise remove entry
* Otherwise remove entry in new_bucket_id if it has finished already. * in new_bucket_id if it has finished already.
*/ */
if (new_bucket_id < 0 || if (new_bucket_id < 0 ||
(entry->key.bucket_id == new_bucket_id && (entry->key.bucket_id == new_bucket_id &&
(entry->counters.state == PGSS_FINISHED || entry->counters.state == PGSS_ERROR))) (entry->counters.state == PGSS_FINISHED || entry->counters.state == PGSS_ERROR)))
{ {
if (new_bucket_id == -1) { if (new_bucket_id == -1)
/* pg_stat_monitor_reset(), remove entry from query hash table too. */ {
/*
* pg_stat_monitor_reset(), remove entry from query hash table
* too.
*/
hash_search(pgss_query_hash, &(entry->key.queryid), HASH_REMOVE, NULL); hash_search(pgss_query_hash, &(entry->key.queryid), HASH_REMOVE, NULL);
} }
@ -201,11 +206,10 @@ hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_bu
} }
/* /*
* If we detect a pending query residing in the previous bucket id, * If we detect a pending query residing in the previous bucket id, we
* we add it to a list of pending elements to be moved to the new * add it to a list of pending elements to be moved to the new bucket
* bucket id. * id. Can't update the hash table while iterating it inside this
* Can't update the hash table while iterating it inside this loop, * loop, as this may introduce all sort of problems.
* as this may introduce all sort of problems.
*/ */
if (old_bucket_id != -1 && entry->key.bucket_id == old_bucket_id) if (old_bucket_id != -1 && entry->key.bucket_id == old_bucket_id)
{ {
@ -214,18 +218,22 @@ hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_bu
entry->counters.state == PGSS_EXEC) entry->counters.state == PGSS_EXEC)
{ {
pgssEntry *bkp_entry = malloc(sizeof(pgssEntry)); pgssEntry *bkp_entry = malloc(sizeof(pgssEntry));
if (!bkp_entry) if (!bkp_entry)
{ {
elog(DEBUG1, "hash_entry_dealloc: out of memory"); elog(DEBUG1, "hash_entry_dealloc: out of memory");
/* /*
* No memory, If the entry has calls > 1 then we change the state to finished, * No memory, If the entry has calls > 1 then we change
* as the pending query will likely finish execution during the new bucket * the state to finished, as the pending query will likely
* time window. The pending query will vanish in this case, can't list it * finish execution during the new bucket time window. The
* pending query will vanish in this case, can't list it
* until it completes. * until it completes.
* *
* If there is only one call to the query and it's pending, remove the * If there is only one call to the query and it's
* entry from the previous bucket and allow it to finish in the new bucket, * pending, remove the entry from the previous bucket and
* in order to avoid the query living in the old bucket forever. * allow it to finish in the new bucket, in order to avoid
* the query living in the old bucket forever.
*/ */
if (entry->counters.calls.calls > 1) if (entry->counters.calls.calls > 1)
entry->counters.state = PGSS_FINISHED; entry->counters.state = PGSS_FINISHED;
@ -244,14 +252,16 @@ hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_bu
pending_entries = lappend(pending_entries, bkp_entry); pending_entries = lappend(pending_entries, bkp_entry);
/* /*
* If the entry has calls > 1 then we change the state to finished in * If the entry has calls > 1 then we change the state to
* the previous bucket, as the pending query will likely finish execution * finished in the previous bucket, as the pending query will
* during the new bucket time window. Can't remove it from the previous bucket * likely finish execution during the new bucket time window.
* as it may have many calls and we would lose the query statistics. * Can't remove it from the previous bucket as it may have
* many calls and we would lose the query statistics.
* *
* If there is only one call to the query and it's pending, remove the entry * If there is only one call to the query and it's pending,
* from the previous bucket and allow it to finish in the new bucket, * remove the entry from the previous bucket and allow it to
* in order to avoid the query living in the old bucket forever. * finish in the new bucket, in order to avoid the query
* living in the old bucket forever.
*/ */
if (entry->counters.calls.calls > 1) if (entry->counters.calls.calls > 1)
entry->counters.state = PGSS_FINISHED; entry->counters.state = PGSS_FINISHED;
@ -262,10 +272,11 @@ hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_bu
} }
/* /*
* Iterate over the list of pending queries in order * Iterate over the list of pending queries in order to add them back to
* to add them back to the hash table with the updated bucket id. * the hash table with the updated bucket id.
*/ */
foreach (pending_entry, pending_entries) { foreach(pending_entry, pending_entries)
{
bool found = false; bool found = false;
pgssEntry *new_entry; pgssEntry *new_entry;
pgssEntry *old_entry = (pgssEntry *) lfirst(pending_entry); pgssEntry *old_entry = (pgssEntry *) lfirst(pending_entry);

File diff suppressed because it is too large Load Diff

View File

@ -104,7 +104,8 @@
#define MAX_ENUM_OPTIONS 6 #define MAX_ENUM_OPTIONS 6
typedef struct GucVariables typedef struct GucVariables
{ {
enum config_type type; /* PGC_BOOL, PGC_INT, PGC_REAL, PGC_STRING, PGC_ENUM */ enum config_type type; /* PGC_BOOL, PGC_INT, PGC_REAL, PGC_STRING,
* PGC_ENUM */
int guc_variable; int guc_variable;
char guc_name[TEXT_LEN]; char guc_name[TEXT_LEN];
char guc_desc[TEXT_LEN]; char guc_desc[TEXT_LEN];
@ -213,13 +214,16 @@ typedef struct pgssHashKey
typedef struct QueryInfo typedef struct QueryInfo
{ {
uint64 parentid; /* parent queryid of current query*/ uint64 parentid; /* parent queryid of current query */
int64 type; /* type of query, options are query, info, warning, error, fatal */ int64 type; /* type of query, options are query, info,
* warning, error, fatal */
char application_name[APPLICATIONNAME_LEN]; char application_name[APPLICATIONNAME_LEN];
char comments[COMMENTS_LEN]; char comments[COMMENTS_LEN];
char relations[REL_LST][REL_LEN]; /* List of relation involved in the query */ char relations[REL_LST][REL_LEN]; /* List of relation involved
* in the query */
int num_relations; /* Number of relation in the query */ int num_relations; /* Number of relation in the query */
CmdType cmd_type; /* query command type SELECT/UPDATE/DELETE/INSERT */ CmdType cmd_type; /* query command type
* SELECT/UPDATE/DELETE/INSERT */
} QueryInfo; } QueryInfo;
typedef struct ErrorInfo typedef struct ErrorInfo
@ -281,7 +285,8 @@ typedef struct Counters
SysInfo sysinfo; SysInfo sysinfo;
ErrorInfo error; ErrorInfo error;
Wal_Usage walusage; Wal_Usage walusage;
int resp_calls[MAX_RESPONSE_BUCKET]; /* execution time's in msec */ int resp_calls[MAX_RESPONSE_BUCKET]; /* execution time's in
* msec */
uint64 state; /* query state */ uint64 state; /* query state */
} Counters; } Counters;
@ -312,16 +317,19 @@ typedef struct pgssSharedState
pg_atomic_uint64 current_wbucket; pg_atomic_uint64 current_wbucket;
pg_atomic_uint64 prev_bucket_sec; pg_atomic_uint64 prev_bucket_sec;
uint64 bucket_entry[MAX_BUCKETS]; uint64 bucket_entry[MAX_BUCKETS];
char bucket_start_time[MAX_BUCKETS][60]; /* start time of the bucket */ char bucket_start_time[MAX_BUCKETS][60]; /* start time of the
LWLock *errors_lock; /* protects errors hashtable search/modification */ * bucket */
LWLock *errors_lock; /* protects errors hashtable
* search/modification */
/* /*
* These variables are used when pgsm_overflow_target is ON. * These variables are used when pgsm_overflow_target is ON.
* *
* overflow is set to true when the query buffer overflows. * overflow is set to true when the query buffer overflows.
* *
* n_bucket_cycles counts the number of times we changed bucket * n_bucket_cycles counts the number of times we changed bucket since the
* since the query buffer overflowed. When it reaches pgsm_max_buckets * query buffer overflowed. When it reaches pgsm_max_buckets we remove the
* we remove the dump file, also reset the counter. * dump file, also reset the counter.
* *
* This allows us to avoid having a large file on disk that would also * This allows us to avoid having a large file on disk that would also
* slowdown queries to the pg_stat_monitor view. * slowdown queries to the pg_stat_monitor view.
@ -350,6 +358,7 @@ typedef struct LocationLen
int location; /* start offset in query text */ int location; /* start offset in query text */
int length; /* length in bytes, or -1 to ignore */ int length; /* length in bytes, or -1 to ignore */
} LocationLen; } LocationLen;
/* /*
* Working state for computing a query jumble and producing a normalized * Working state for computing a query jumble and producing a normalized
* query string * query string
@ -394,7 +403,7 @@ bool IsHashInitialize(void);
void pgss_shmem_startup(void); void pgss_shmem_startup(void);
void pgss_shmem_shutdown(int code, Datum arg); void pgss_shmem_shutdown(int code, Datum arg);
int pgsm_get_bucket_size(void); int pgsm_get_bucket_size(void);
pgssSharedState* pgsm_get_ss(void); pgssSharedState *pgsm_get_ss(void);
HTAB *pgsm_get_plan_hash(void); HTAB *pgsm_get_plan_hash(void);
HTAB *pgsm_get_hash(void); HTAB *pgsm_get_hash(void);
HTAB *pgsm_get_query_hash(void); HTAB *pgsm_get_query_hash(void);
@ -404,18 +413,20 @@ void hash_query_entryies_reset(void);
void hash_query_entries(); void hash_query_entries();
void hash_query_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer[]); void hash_query_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer[]);
void hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer); void hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer);
pgssEntry* hash_entry_alloc(pgssSharedState *pgss, pgssHashKey *key, int encoding); pgssEntry *hash_entry_alloc(pgssSharedState *pgss, pgssHashKey *key, int encoding);
Size hash_memsize(void); Size hash_memsize(void);
int read_query_buffer(int bucket_id, uint64 queryid, char *query_txt, size_t pos); int read_query_buffer(int bucket_id, uint64 queryid, char *query_txt, size_t pos);
uint64 read_query(unsigned char *buf, uint64 queryid, char * query, size_t pos); uint64 read_query(unsigned char *buf, uint64 queryid, char *query, size_t pos);
void pgss_startup(void); void pgss_startup(void);
void set_qbuf(unsigned char *); void set_qbuf(unsigned char *);
/* hash_query.c */ /* hash_query.c */
void pgss_startup(void); void pgss_startup(void);
/*---- GUC variables ----*/ /*---- GUC variables ----*/
typedef enum { typedef enum
{
PSGM_TRACK_NONE = 0, /* track no statements */ PSGM_TRACK_NONE = 0, /* track no statements */
PGSM_TRACK_TOP, /* only top level statements */ PGSM_TRACK_TOP, /* only top level statements */
PGSM_TRACK_ALL /* all statements, including nested ones */ PGSM_TRACK_ALL /* all statements, including nested ones */
@ -452,7 +463,8 @@ static const struct config_enum_entry track_options[] =
* STATS_START and STATS_END are used only to delimit the range. * STATS_START and STATS_END are used only to delimit the range.
* STATS_END is also the length of the valid items in the enum. * STATS_END is also the length of the valid items in the enum.
*/ */
enum pg_hook_stats_id { enum pg_hook_stats_id
{
STATS_START = -1, STATS_START = -1,
STATS_PGSS_POST_PARSE_ANALYZE, STATS_PGSS_POST_PARSE_ANALYZE,
STATS_PGSS_EXECUTORSTART, STATS_PGSS_EXECUTORSTART,
@ -469,7 +481,8 @@ enum pg_hook_stats_id {
}; };
/* Hold time to execute statistics for a hook. */ /* Hold time to execute statistics for a hook. */
struct pg_hook_stats_t { struct pg_hook_stats_t
{
char hook_name[64]; char hook_name[64];
double min_time; double min_time;
double max_time; double max_time;

View File

@ -44,7 +44,8 @@ PG_FUNCTION_INFO_V1(pg_stat_monitor_reset_errors);
static HTAB *pgsm_errors_ht = NULL; static HTAB *pgsm_errors_ht = NULL;
void psgm_errors_init(void) void
psgm_errors_init(void)
{ {
HASHCTL info; HASHCTL info;
#if PG_VERSION_NUM >= 140000 #if PG_VERSION_NUM >= 140000
@ -64,12 +65,14 @@ void psgm_errors_init(void)
flags); flags);
} }
size_t pgsm_errors_size(void) size_t
pgsm_errors_size(void)
{ {
return hash_estimate_size(PSGM_ERRORS_MAX, sizeof(ErrorEntry)); return hash_estimate_size(PSGM_ERRORS_MAX, sizeof(ErrorEntry));
} }
void pgsm_log(PgsmLogSeverity severity, const char *format, ...) void
pgsm_log(PgsmLogSeverity severity, const char *format,...)
{ {
char key[ERROR_MSG_MAX_LEN]; char key[ERROR_MSG_MAX_LEN];
ErrorEntry *entry; ErrorEntry *entry;
@ -94,6 +97,7 @@ void pgsm_log(PgsmLogSeverity severity, const char *format, ...)
if (!entry) if (!entry)
{ {
LWLockRelease(pgss->errors_lock); LWLockRelease(pgss->errors_lock);
/* /*
* We're out of memory, can't track this error message. * We're out of memory, can't track this error message.
*/ */
@ -204,6 +208,7 @@ pg_stat_monitor_errors(PG_FUNCTION_ARGS)
Datum values[4]; Datum values[4];
bool nulls[4]; bool nulls[4];
int i = 0; int i = 0;
memset(values, 0, sizeof(values)); memset(values, 0, sizeof(values));
memset(nulls, 0, sizeof(nulls)); memset(nulls, 0, sizeof(nulls));
@ -219,5 +224,5 @@ pg_stat_monitor_errors(PG_FUNCTION_ARGS)
/* clean up and return the tuplestore */ /* clean up and return the tuplestore */
tuplestore_donestoring(tupstore); tuplestore_donestoring(tupstore);
return (Datum)0; return (Datum) 0;
} }