11diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
2- indexb9302ac..95f7da2 100644
2+ indexb0dd7d1..1f14b0d 100644
33--- a/src/backend/storage/ipc/procsignal.c
44+++ b/src/backend/storage/ipc/procsignal.c
5- @@ -27,6 +27,7 @@
6- #include "storage/shmem.h"
7- #include "storage/sinval.h"
8- #include "tcop/tcopprot.h"
9- + #include "utils/memutils.h"
10-
11-
12- /*
13- @@ -60,12 +61,17 @@ typedef struct
5+ @@ -60,12 +60,17 @@ typedef struct
146 */
157 #define NumProcSignalSlots(MaxBackends + NUM_AUXPROCTYPES)
168
@@ -28,12 +20,12 @@ index b9302ac..95f7da2 100644
2820 /*
2921 * ProcSignalShmemSize
3022 *Compute space needed for procsignal's shared memory
31- @@ -166,6 +172 ,57 @@ CleanupProcSignalState(int status, Datum arg)
23+ @@ -166,6 +171 ,57 @@ CleanupProcSignalState(int status, Datum arg)
3224 }
3325
3426 /*
3527+ * RegisterCustomProcSignalHandler
36- + * Assign specific handlerfor custom process signal with new ProcSignalReason key.
28+ + * Assign specific handlerof custom process signal with new ProcSignalReason key.
3729+ * Return INVALID_PROCSIGNAL if all custom signals have been assigned.
3830+ */
3931+ ProcSignalReason
@@ -62,7 +54,7 @@ index b9302ac..95f7da2 100644
6254+ {
6355+ ProcSignalHandler_type old;
6456+
65- + AssertArg (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
57+ + Assert (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
6658+
6759+ old = CustomHandlers[reason - PROCSIG_CUSTOM_1];
6860+ CustomHandlers[reason - PROCSIG_CUSTOM_1] = handler;
@@ -77,7 +69,7 @@ index b9302ac..95f7da2 100644
7769+ ProcSignalHandler_type
7870+ GetCustomProcSignalHandler(ProcSignalReason reason)
7971+ {
80- + AssertArg (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
72+ + Assert (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
8173+
8274+ return CustomHandlers[reason - PROCSIG_CUSTOM_1];
8375+ }
@@ -86,7 +78,7 @@ index b9302ac..95f7da2 100644
8678 * SendProcSignal
8779 *Send a signal to a Postgres process
8880 *
89- @@ -260,7 +317 ,8 @@ CheckProcSignal(ProcSignalReason reason)
81+ @@ -260,7 +316 ,8 @@ CheckProcSignal(ProcSignalReason reason)
9082 void
9183 procsignal_sigusr1_handler(SIGNAL_ARGS)
9284 {
@@ -96,7 +88,7 @@ index b9302ac..95f7da2 100644
9688
9789 if (CheckProcSignal(PROCSIG_CATCHUP_INTERRUPT))
9890 HandleCatchupInterrupt();
99- @@ -292,9 +350,87 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
91+ @@ -292,9 +349,55 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
10092 if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
10193 RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
10294
@@ -119,7 +111,7 @@ index b9302ac..95f7da2 100644
119111+ {
120112+ intsave_errno = errno;
121113+
122- + AssertArg (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
114+ + Assert (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
123115+
124116+ /* set interrupt flags */
125117+ InterruptPending = true;
@@ -140,31 +132,6 @@ index b9302ac..95f7da2 100644
140132+ CheckAndHandleCustomSignals(void)
141133+ {
142134+ int i;
143- + MemoryContext oldcontext;
144- +
145- + static MemoryContext hcs_context = NULL;
146- +
147- + /*
148- + * This is invoked from ProcessInterrupts(), and since some of the
149- + * functions it calls contain CHECK_FOR_INTERRUPTS(), there is a potential
150- + * for recursive calls if more signals are received while this runs, so
151- + * let's block interrupts until done.
152- + */
153- + HOLD_INTERRUPTS();
154- +
155- + /*
156- + * Moreover, CurrentMemoryContext might be pointing almost anywhere. We
157- + * don't want to risk leaking data into long-lived contexts, so let's do
158- + * our work here in a private context that we can reset on each use.
159- + */
160- + if (hcs_context == NULL)/* first time through? */
161- + hcs_context = AllocSetContextCreate(TopMemoryContext,
162- + "HandleCustomSignals",
163- + ALLOCSET_DEFAULT_SIZES);
164- + else
165- + MemoryContextReset(hcs_context);
166- +
167- + oldcontext = MemoryContextSwitchTo(hcs_context);
168135+
169136+ for (i = 0; i < NUM_CUSTOM_PROCSIGNALS; i++)
170137+ if (CustomSignalPendings[i])
@@ -176,19 +143,12 @@ index b9302ac..95f7da2 100644
176143+ if (handler)
177144+ handler();
178145+ }
179- +
180- + MemoryContextSwitchTo(oldcontext);
181- +
182- + /* Might as well clear the context on our way out */
183- + MemoryContextReset(hcs_context);
184- +
185- + RESUME_INTERRUPTS();
186146+ }
187147diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
188- index63a1994..0dfad33 100644
148+ index7a9ada2..e9698e1 100644
189149--- a/src/backend/tcop/postgres.c
190150+++ b/src/backend/tcop/postgres.c
191- @@ -3012 ,6 +3012 ,8 @@ ProcessInterrupts(void)
151+ @@ -3053 ,6 +3053 ,8 @@ ProcessInterrupts(void)
192152
193153 if (ParallelMessagePending)
194154 HandleParallelMessages();
@@ -198,19 +158,19 @@ index 63a1994..0dfad33 100644
198158
199159
200160diff --git a/src/include/storage/procsignal.h b/src/include/storage/procsignal.h
201- index20bb05b..9b16eb3 100644
161+ index6db0d69..ceadc09 100644
202162--- a/src/include/storage/procsignal.h
203163+++ b/src/include/storage/procsignal.h
204- @@ -17,6 +17,8 @@
205- #include "storage/backendid.h"
164+ @@ -16,7 +16,7 @@
206165
166+ #include "storage/backendid.h"
207167
168+ -
208169+ #define NUM_CUSTOM_PROCSIGNALS 64
209- +
210170 /*
211171 * Reasons for signalling a Postgres child process (a backend or an auxiliary
212172 * process, like checkpointer). We can cope with concurrent signals for different
213- @@ -29,6 +31 ,8 @@
173+ @@ -29,6 +29 ,8 @@
214174 */
215175 typedef enum
216176 {
@@ -219,7 +179,7 @@ index 20bb05b..9b16eb3 100644
219179 PROCSIG_CATCHUP_INTERRUPT,/* sinval catchup interrupt */
220180 PROCSIG_NOTIFY_INTERRUPT,/* listen/notify interrupt */
221181 PROCSIG_PARALLEL_MESSAGE,/* message from cooperating parallel backend */
222- @@ -42,9 +46 ,20 @@ typedef enum
182+ @@ -42,9 +44 ,20 @@ typedef enum
223183 PROCSIG_RECOVERY_CONFLICT_BUFFERPIN,
224184 PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK,
225185
@@ -240,7 +200,7 @@ index 20bb05b..9b16eb3 100644
240200 /*
241201 * prototypes for functions in procsignal.c
242202 */
243- @@ -52,9 +67 ,15 @@ extern Size ProcSignalShmemSize(void);
203+ @@ -52,9 +65 ,15 @@ extern Size ProcSignalShmemSize(void);
244204 extern void ProcSignalShmemInit(void);
245205
246206 extern void ProcSignalInit(int pss_idx);