On 21/04/17 04:37, Petr Jelinek wrote:
> On 21/04/17 04:32, Craig Ringer wrote:
>> On 21 April 2017 at 10:20, Petr Jelinek <petr.jeli...@2ndquadrant.com> wrote:
>>> On 21/04/17 03:40, Andres Freund wrote:
>>>>
>>>> Since [1] walsender (not receiver as commit message says) can execute
>>>> SQL queries.  While doing some testing of [2] I noticed that SQL queries
>>>> in walsender get stuck if parallelism is used - I have not investigated
>>>> why that is yet, but it surely is an issue.  On first blush I'd suspect
>>>> that some signalling is not wired up correctly (cf. am_walsender branches
>>>> in PostgresMain() and such).
>>>
>>> Looks like SIGUSR1 being different is problem here - it's normally used
>>> to . I also noticed that we don't handle SIGINT (query cancel).
>>>
>>> I'll write proper patch but can you try to just use
>>> procsignal_sigusr1_handler for SIGUSR1 in walsender.c to see if it fixes
>>> the issue?
>>
>> That's what my recovery conflicts for logical decoding on standby
>> patch does, FWIW.
>>
>> I haven't found any issues yet..
>>
> 
> Ah I knew I've seen that change somewhere. I thought it was either in my
> patch or master which is why I thought it's working fine already.
> 

Here is patch. I changed both SIGINT and SIGUSR1 handlers, afaics it
does not break anything for existing walsender usage.

-- 
  Petr Jelinek                  http://www.2ndQuadrant.com/
  PostgreSQL Development, 24x7 Support, Training & Services
From f59218135092bec9a64cf86b75f1f62a0271d448 Mon Sep 17 00:00:00 2001
From: Petr Jelinek <pjmo...@pjmodos.net>
Date: Fri, 21 Apr 2017 05:11:30 +0200
Subject: [PATCH] Handle signals correctly in walsender

Since we now support SQL queries in walsender, we also need to handle
SIGINT for query cancel and SIGUSR1 for IPC.
---
 src/backend/replication/logical/launcher.c |  2 +-
 src/backend/replication/walsender.c        | 16 ++--------------
 2 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/src/backend/replication/logical/launcher.c 
b/src/backend/replication/logical/launcher.c
index 761fbfa..e9dd886 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -254,7 +254,7 @@ logicalrep_worker_launch(Oid dbid, Oid subid, const char 
*subname, Oid userid,
        BackgroundWorker        bgw;
        BackgroundWorkerHandle *bgw_handle;
        int                                     i;
-       int                                     slot;
+       int                                     slot = 0;
        LogicalRepWorker   *worker = NULL;
        int                                     nsyncworkers = 0;
        TimestampTz                     now = GetCurrentTimestamp();
diff --git a/src/backend/replication/walsender.c 
b/src/backend/replication/walsender.c
index b4ce75a..78369ae 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -212,7 +212,6 @@ static struct
 
 /* Signal handlers */
 static void WalSndSigHupHandler(SIGNAL_ARGS);
-static void WalSndXLogSendHandler(SIGNAL_ARGS);
 static void WalSndLastCycleHandler(SIGNAL_ARGS);
 
 /* Prototypes for private functions */
@@ -2830,17 +2829,6 @@ WalSndSigHupHandler(SIGNAL_ARGS)
        errno = save_errno;
 }
 
-/* SIGUSR1: set flag to send WAL records */
-static void
-WalSndXLogSendHandler(SIGNAL_ARGS)
-{
-       int                     save_errno = errno;
-
-       latch_sigusr1_handler();
-
-       errno = save_errno;
-}
-
 /* SIGUSR2: set flag to do a last cycle and shut down afterwards */
 static void
 WalSndLastCycleHandler(SIGNAL_ARGS)
@@ -2869,12 +2857,12 @@ WalSndSignals(void)
        /* Set up signal handlers */
        pqsignal(SIGHUP, WalSndSigHupHandler);          /* set flag to read 
config
                                                                                
                 * file */
-       pqsignal(SIGINT, SIG_IGN);      /* not used */
+       pqsignal(SIGINT, StatementCancelHandler);       /* query cancel */
        pqsignal(SIGTERM, die);         /* request shutdown */
        pqsignal(SIGQUIT, quickdie);    /* hard crash time */
        InitializeTimeouts();           /* establishes SIGALRM handler */
        pqsignal(SIGPIPE, SIG_IGN);
-       pqsignal(SIGUSR1, WalSndXLogSendHandler);       /* request WAL sending 
*/
+       pqsignal(SIGUSR1, procsignal_sigusr1_handler);
        pqsignal(SIGUSR2, WalSndLastCycleHandler);      /* request a last cycle 
and
                                                                                
                 * shutdown */
 
-- 
2.7.4

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to