-
Notifications
You must be signed in to change notification settings - Fork 26
/
pg_query_state.h
95 lines (81 loc) · 2.32 KB
/
pg_query_state.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* pg_query_state.h
* Headers for pg_query_state extension.
*
* Copyright (c) 2016-2024, Postgres Professional
*
* IDENTIFICATION
* contrib/pg_query_state/pg_query_state.h
*/
#ifndef __PG_QUERY_STATE_H__
#define __PG_QUERY_STATE_H__
#include <postgres.h>
#include "commands/explain.h"
#include "nodes/pg_list.h"
#include "storage/procarray.h"
#include "storage/shm_mq.h"
#define QUEUE_SIZE (16 * 1024)
#define MSG_MAX_SIZE 1024
#define WRITING_DELAY (100 * 1000) /* 100ms */
#define NUM_OF_ATTEMPTS 6
#define TIMINIG_OFF_WARNING 1
#define BUFFERS_OFF_WARNING 2
#define PG_QS_MODULE_KEY 0xCA94B108
#define PG_QS_RCV_KEY 0
#define PG_QS_SND_KEY 1
/* Receive timeout should be larger than send timeout to let workers stop waiting before polling process */
#define MAX_RCV_TIMEOUT 6000 /* 6 seconds */
#define MAX_SND_TIMEOUT 3000 /* 3 seconds */
/*
* Delay for receiving parts of full message (in case SHM_MQ_WOULD_BLOCK code),
* should be tess than MAX_RCV_TIMEOUT
*/
#define PART_RCV_DELAY 1000 /* 1 second */
/*
* Result status on query state request from asked backend
*/
typedef enum
{
QUERY_NOT_RUNNING, /* Backend doesn't execute any query */
STAT_DISABLED, /* Collection of execution statistics is disabled */
QS_RETURNED /* Backend succx[esfully returned its query state */
} PG_QS_RequestResult;
/*
* Format of transmited data through message queue
*/
typedef struct
{
int reqid;
int length; /* size of message record, for sanity check */
PGPROC *proc;
PG_QS_RequestResult result_code;
int warnings; /* bitmap of warnings */
int stack_depth;
char stack[FLEXIBLE_ARRAY_MEMBER]; /* sequencially laid out stack frames in form of
text records */
} shm_mq_msg;
#define BASE_SIZEOF_SHM_MQ_MSG (offsetof(shm_mq_msg, stack_depth))
/* pg_query_state arguments */
typedef struct
{
int reqid;
bool verbose;
bool costs;
bool timing;
bool buffers;
bool triggers;
ExplainFormat format;
} pg_qs_params;
/* pg_query_state */
extern bool pg_qs_enable;
extern bool pg_qs_timing;
extern bool pg_qs_buffers;
extern List *QueryDescStack;
extern pg_qs_params *params;
extern shm_mq *mq;
/* signal_handler.c */
extern void SendQueryState(void);
extern void DetachPeer(void);
extern void UnlockShmem(LOCKTAG *tag);
extern void LockShmem(LOCKTAG *tag, uint32 key);
#endif