Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita5afb51

Browse files
authored
Merge pull request#49 from postgrespro/PGPRO-9728
pg_query_state update for PostgreSQL 16
2 parentse8cde16 +d099f68 commita5afb51

15 files changed

+515
-12
lines changed

‎.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ notifications:
2222
on_failure:always
2323

2424
env:
25+
-PG_VERSION=16 LEVEL=hardcore USE_TPCDS=0
26+
-PG_VERSION=16
2527
-PG_VERSION=15 LEVEL=hardcore USE_TPCDS=0
2628
-PG_VERSION=15
2729
-PG_VERSION=14 LEVEL=hardcore USE_TPCDS=0

‎Dockerfile.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN apk add --no-cache \
66
perl perl-ipc-run \
77
make musl-dev gcc bison flex coreutils \
88
zlib-dev libedit-dev \
9-
clang clang-analyzer linux-headers \
9+
icu-devclang clang-analyzer linux-headers \
1010
python3 python3-dev py3-virtualenv;
1111

1212

‎LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pg_query_state is released under the PostgreSQL License, a liberal Open Source license, similar to the BSD or MIT licenses.
22

3-
Copyright (c) 2016-2023, Postgres Professional
3+
Copyright (c) 2016-2024, Postgres Professional
44
Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
55
Portions Copyright (c) 1994, The Regents of the University of California
66

‎README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,25 @@ Using this module there can help in the following things:
1515
- overwatch the query execution
1616

1717
##Installation
18-
To install`pg_query_state`, please apply corresponding patches`custom_signal_(PG_VERSION).patch` and`runtime_explain_(PG_VERSION).patch` (or`runtime_explain.patch` for PG version <= 10.0) in`patches/` directory to reqired stable version of PostgreSQL and rebuild PostgreSQL.
18+
To install`pg_query_state`, please apply corresponding patches`custom_signal_(PG_VERSION).patch` and`runtime_explain_(PG_VERSION).patch` (or`runtime_explain.patch` for PG version <= 10.0) from the`patches/` directory to reqired stable version of PostgreSQL and rebuild PostgreSQL.
19+
20+
To do this, run the following commands from the postgresql directory:
21+
```
22+
patch -p1 < path_to_pg_query_state_folder/patches/runtime_explain_(PG_VERSION).patch
23+
patch -p1 < path_to_pg_query_state_folder/patches/custom_signal_(PG_VERSION).patch
24+
```
1925

2026
Then execute this in the module's directory:
2127
```
2228
make install USE_PGXS=1
2329
```
30+
To execute the command correctly, make sure you have the PATH or PG_CONFIG variable set.
31+
```
32+
export PATH=path_to_your_bin_folder:$PATH
33+
# or
34+
export PG_CONFIG=path_to_your_bin_folder/pg_config
35+
```
36+
2437
Add module name to the`shared_preload_libraries` parameter in`postgresql.conf`:
2538
```
2639
shared_preload_libraries = 'pg_query_state'

‎docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
tests:
1+
services:
2+
tests:
23
build:.

‎patches/custom_signals_16.0.patch

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
2+
index c85cb5cc18..37ae4b3759 100644
3+
--- a/src/backend/storage/ipc/procsignal.c
4+
+++ b/src/backend/storage/ipc/procsignal.c
5+
@@ -6,6 +6,7 @@
6+
*
7+
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
8+
* Portions Copyright (c) 1994, Regents of the University of California
9+
+ * Portions Copyright (c) 2024, Postgres Professional
10+
*
11+
* IDENTIFICATION
12+
* src/backend/storage/ipc/procsignal.c
13+
@@ -97,6 +98,13 @@ typedef struct
14+
#define BARRIER_CLEAR_BIT(flags, type) \
15+
((flags) &= ~(((uint32) 1) << (uint32) (type)))
16+
17+
+#define IsCustomProcSignalReason(reason) \
18+
+((reason) >= PROCSIG_CUSTOM_1 && (reason) <= PROCSIG_CUSTOM_N)
19+
+
20+
+static bool CustomSignalPendings[NUM_CUSTOM_PROCSIGNALS];
21+
+static bool CustomSignalProcessing[NUM_CUSTOM_PROCSIGNALS];
22+
+static ProcSignalHandler_type CustomInterruptHandlers[NUM_CUSTOM_PROCSIGNALS];
23+
+
24+
static ProcSignalHeader *ProcSignal = NULL;
25+
static ProcSignalSlot *MyProcSignalSlot = NULL;
26+
27+
@@ -104,6 +112,8 @@ static bool CheckProcSignal(ProcSignalReason reason);
28+
static void CleanupProcSignalState(int status, Datum arg);
29+
static void ResetProcSignalBarrierBits(uint32 flags);
30+
31+
+static void CheckAndSetCustomSignalInterrupts(void);
32+
+
33+
/*
34+
* ProcSignalShmemSize
35+
*Compute space needed for ProcSignal's shared memory
36+
@@ -247,6 +257,36 @@ CleanupProcSignalState(int status, Datum arg)
37+
slot->pss_pid = 0;
38+
}
39+
40+
+/*
41+
+ * RegisterCustomProcSignalHandler
42+
+ *Assign specific handler of custom process signal with new
43+
+ *ProcSignalReason key.
44+
+ *
45+
+ * This function has to be called in _PG_init function of extensions at the
46+
+ * stage of loading shared preloaded libraries. Otherwise it throws fatal error.
47+
+ *
48+
+ * Return INVALID_PROCSIGNAL if all slots for custom signals are occupied.
49+
+ */
50+
+ProcSignalReason
51+
+RegisterCustomProcSignalHandler(ProcSignalHandler_type handler)
52+
+{
53+
+ProcSignalReason reason;
54+
+
55+
+if (!process_shared_preload_libraries_in_progress)
56+
+ereport(FATAL, (errcode(ERRCODE_INTERNAL_ERROR),
57+
+errmsg("cannot register custom signal after startup")));
58+
+
59+
+/* Iterate through custom signal slots to find a free one */
60+
+for (reason = PROCSIG_CUSTOM_1; reason <= PROCSIG_CUSTOM_N; reason++)
61+
+if (!CustomInterruptHandlers[reason - PROCSIG_CUSTOM_1])
62+
+{
63+
+CustomInterruptHandlers[reason - PROCSIG_CUSTOM_1] = handler;
64+
+return reason;
65+
+}
66+
+
67+
+return INVALID_PROCSIGNAL;
68+
+}
69+
+
70+
/*
71+
* SendProcSignal
72+
*Send a signal to a Postgres process
73+
@@ -682,7 +722,72 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
74+
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
75+
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
76+
77+
+CheckAndSetCustomSignalInterrupts();
78+
+
79+
SetLatch(MyLatch);
80+
81+
errno = save_errno;
82+
}
83+
+
84+
+/*
85+
+ * Handle receipt of an interrupt indicating any of custom process signals.
86+
+ */
87+
+static void
88+
+CheckAndSetCustomSignalInterrupts()
89+
+{
90+
+ProcSignalReasonreason;
91+
+
92+
+for (reason = PROCSIG_CUSTOM_1; reason <= PROCSIG_CUSTOM_N; reason++)
93+
+{
94+
+if (CheckProcSignal(reason))
95+
+{
96+
+
97+
+/* set interrupt flags */
98+
+InterruptPending = true;
99+
+CustomSignalPendings[reason - PROCSIG_CUSTOM_1] = true;
100+
+}
101+
+}
102+
+
103+
+SetLatch(MyLatch);
104+
+}
105+
+
106+
+/*
107+
+ * CheckAndHandleCustomSignals
108+
+ *Check custom signal flags and call handler assigned to that signal
109+
+ *if it is not NULL
110+
+ *
111+
+ * This function is called within CHECK_FOR_INTERRUPTS if interrupt occurred.
112+
+ */
113+
+void
114+
+CheckAndHandleCustomSignals(void)
115+
+{
116+
+int i;
117+
+
118+
+/*
119+
+ * This is invoked from ProcessInterrupts(), and since some of the
120+
+ * functions it calls contain CHECK_FOR_INTERRUPTS(), there is a potential
121+
+ * for recursive calls if more signals are received while this runs, so
122+
+ * let's block interrupts until done.
123+
+ */
124+
+HOLD_INTERRUPTS();
125+
+
126+
+/* Check on expiring of custom signals and call its handlers if exist */
127+
+for (i = 0; i < NUM_CUSTOM_PROCSIGNALS; i++)
128+
+{
129+
+if (!CustomSignalProcessing[i] && CustomSignalPendings[i])
130+
+{
131+
+ProcSignalHandler_type handler;
132+
+
133+
+CustomSignalPendings[i] = false;
134+
+handler = CustomInterruptHandlers[i];
135+
+if (handler != NULL)
136+
+{
137+
+CustomSignalProcessing[i] = true;
138+
+handler();
139+
+CustomSignalProcessing[i] = false;
140+
+}
141+
+}
142+
+}
143+
+
144+
+RESUME_INTERRUPTS();
145+
+}
146+
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
147+
index 36cc99ec9c..a3acce427a 100644
148+
--- a/src/backend/tcop/postgres.c
149+
+++ b/src/backend/tcop/postgres.c
150+
@@ -3442,6 +3442,8 @@ ProcessInterrupts(void)
151+
if (ParallelMessagePending)
152+
HandleParallelMessages();
153+
154+
+CheckAndHandleCustomSignals();
155+
+
156+
if (LogMemoryContextPending)
157+
ProcessLogMemoryContextInterrupt();
158+
159+
diff --git a/src/include/storage/procsignal.h b/src/include/storage/procsignal.h
160+
index 2f52100b00..0e31a5771e 100644
161+
--- a/src/include/storage/procsignal.h
162+
+++ b/src/include/storage/procsignal.h
163+
@@ -6,6 +6,7 @@
164+
*
165+
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
166+
* Portions Copyright (c) 1994, Regents of the University of California
167+
+ * Portions Copyright (c) 2024, Postgres Professional
168+
*
169+
* src/include/storage/procsignal.h
170+
*
171+
@@ -17,6 +18,8 @@
172+
#include "storage/backendid.h"
173+
174+
175+
+#define NUM_CUSTOM_PROCSIGNALS 64
176+
+
177+
/*
178+
* Reasons for signaling a Postgres child process (a backend or an auxiliary
179+
* process, like checkpointer). We can cope with concurrent signals for different
180+
@@ -29,6 +32,8 @@
181+
*/
182+
typedef enum
183+
{
184+
+INVALID_PROCSIGNAL = -1,/* Must be first */
185+
+
186+
PROCSIG_CATCHUP_INTERRUPT,/* sinval catchup interrupt */
187+
PROCSIG_NOTIFY_INTERRUPT,/* listen/notify interrupt */
188+
PROCSIG_PARALLEL_MESSAGE,/* message from cooperating parallel backend */
189+
@@ -46,6 +51,14 @@ typedef enum
190+
PROCSIG_RECOVERY_CONFLICT_BUFFERPIN,
191+
PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK,
192+
193+
+PROCSIG_CUSTOM_1,
194+
+/*
195+
+ * PROCSIG_CUSTOM_2,
196+
+ * ...,
197+
+ * PROCSIG_CUSTOM_N-1,
198+
+ */
199+
+PROCSIG_CUSTOM_N = PROCSIG_CUSTOM_1 + NUM_CUSTOM_PROCSIGNALS - 1,
200+
+
201+
NUM_PROCSIGNALS/* Must be last! */
202+
} ProcSignalReason;
203+
204+
@@ -54,6 +67,9 @@ typedef enum
205+
PROCSIGNAL_BARRIER_SMGRRELEASE/* ask smgr to close files */
206+
} ProcSignalBarrierType;
207+
208+
+/* Handler of custom process signal */
209+
+typedef void (*ProcSignalHandler_type) (void);
210+
+
211+
/*
212+
* prototypes for functions in procsignal.c
213+
*/
214+
@@ -61,12 +77,15 @@ extern Size ProcSignalShmemSize(void);
215+
extern void ProcSignalShmemInit(void);
216+
217+
extern void ProcSignalInit(int pss_idx);
218+
+extern ProcSignalReason
219+
+RegisterCustomProcSignalHandler(ProcSignalHandler_type handler);
220+
extern intSendProcSignal(pid_t pid, ProcSignalReason reason,
221+
BackendId backendId);
222+
223+
extern uint64 EmitProcSignalBarrier(ProcSignalBarrierType type);
224+
extern void WaitForProcSignalBarrier(uint64 generation);
225+
extern void ProcessProcSignalBarrier(void);
226+
+extern void CheckAndHandleCustomSignals(void);
227+
228+
extern void procsignal_sigusr1_handler(SIGNAL_ARGS);
229+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp