- Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathpg_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"
#defineQUEUE_SIZE (16 * 1024)
#defineMSG_MAX_SIZE 1024
#defineWRITING_DELAY (100 * 1000) /* 100ms */
#defineNUM_OF_ATTEMPTS 6
#defineTIMINIG_OFF_WARNING 1
#defineBUFFERS_OFF_WARNING 2
#definePG_QS_MODULE_KEY 0xCA94B108
#definePG_QS_RCV_KEY 0
#definePG_QS_SND_KEY 1
/* Receive timeout should be larger than send timeout to let workers stop waiting before polling process */
#defineMAX_RCV_TIMEOUT 6000 /* 6 seconds */
#defineMAX_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
*/
#definePART_RCV_DELAY 1000 /* 1 second */
/*
* Result status on query state request from asked backend
*/
typedefenum
{
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
*/
typedefstruct
{
intreqid;
intlength; /* size of message record, for sanity check */
PGPROC*proc;
PG_QS_RequestResultresult_code;
intwarnings; /* bitmap of warnings */
intstack_depth;
charstack[FLEXIBLE_ARRAY_MEMBER]; /* sequencially laid out stack frames in form of
text records */
} shm_mq_msg;
#defineBASE_SIZEOF_SHM_MQ_MSG (offsetof(shm_mq_msg, stack_depth))
/* pg_query_state arguments */
typedefstruct
{
intreqid;
boolverbose;
boolcosts;
booltiming;
boolbuffers;
booltriggers;
ExplainFormatformat;
} pg_qs_params;
/* pg_query_state */
externboolpg_qs_enable;
externboolpg_qs_timing;
externboolpg_qs_buffers;
externList*QueryDescStack;
externpg_qs_params*params;
externshm_mq*mq;
/* signal_handler.c */
externvoidSendQueryState(void);
externvoidDetachPeer(void);
externvoidUnlockShmem(LOCKTAG*tag);
externvoidLockShmem(LOCKTAG*tag, uint32key);
#endif