Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pFTxy-0007Rt-KR for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Jan 2023 05:48:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pFTxx-0007py-3U for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Jan 2023 05:48:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pFTxw-0007pp-OK for pgsql-hackers@lists.postgresql.org; Wed, 11 Jan 2023 05:48:00 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pFTxu-0000Mc-3i for pgsql-hackers@postgresql.org; Wed, 11 Jan 2023 05:47:59 +0000 Received: by mail-pj1-x102d.google.com with SMTP id m7-20020a17090a730700b00225ebb9cd01so18851650pjk.3 for ; Tue, 10 Jan 2023 21:47:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=mYBi6sVhvRqGFFSjQwlPe17M12oFDeiG2xpTuYFTSzU=; b=JGamImF6SwXJtfEgnA7Q4mnxZVokQQt5yPjzzrQzUETk9zl+rY3GtpxnRR0pRjsvuB ckLELJfaHZjf2yP6lYrohPeF/8oDtfi90GHVGgsEquDum899Ft6PWYLA5lCM3mI4bgNI sIau8qB+stJNUO98oe0Docw1fnLOSB42Ddp/KaTtTVI5eGfHS65OLF7kCOtPSEckcSay /yaYCYy82DfOVTu7yZOh+wGB/jdXslWobbKqMCmGA9ZfMhZd3Q3AHHHfpdtomDk0CIcT 04b/LSMyKfVdEn6ltZSsT2kuU1AahDQuAc+ppiOEAMej6NjXBfsAWANEWFGRGZcjUAbL kGQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mYBi6sVhvRqGFFSjQwlPe17M12oFDeiG2xpTuYFTSzU=; b=tNd3rU9TECw27nuHvo+YvtSZN67R03Ir9I7mwumXCNbF55wqH3lJRJ5Hy1mSwMpdNK wHiEnz69ceueYhNht49whg/nj3w1JXe/XYWUonlKTKcsbE4X+OxbsE4yBfiOBBPQrvkD R0OLixNttSBT0sFozXnmIq0tvz6Y82uvlzDIyKzHythdL/KHfLWyna9ZJyZLv5btVSgI vivVEqPchvQ2uUQVQZfs//++fFS1ZK7mwvZw5k+no+v934dvEcKWoixremm6mt0AE0OJ HEUUy8Hp32dcNt/56gH1Vc/sYORKFzy1TUGEfXtki7Par9oAmbZiPAXTdCU17v+L+T+8 m6Dw== X-Gm-Message-State: AFqh2kq/l4HMbL8VTh7XF8k1BxnrpsmNQbMA8kfWknV+bZj1Txg0c1np pOyAB9pVEE03J67LJkW2d2FjD2NP6uM= X-Google-Smtp-Source: AMrXdXugxrSGTEOCt8nWp7xKWcU89rCykReY9a0UfNo4pWxNIbDKNVGQWqsc31Os1DUKsnQlUirnxg== X-Received: by 2002:a17:903:25d6:b0:188:5e99:d84f with SMTP id jc22-20020a17090325d600b001885e99d84fmr1541421plb.42.1673416076755; Tue, 10 Jan 2023 21:47:56 -0800 (PST) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id f9-20020a170902ce8900b0019258bcf3ffsm9183319plg.56.2023.01.10.21.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 21:47:56 -0800 (PST) Date: Tue, 10 Jan 2023 21:47:54 -0800 From: Nathan Bossart To: Thomas Munro Cc: pgsql-hackers@postgresql.org Subject: Re: delay starting WAL receiver Message-ID: <20230111054754.GA1622234@nathanxps13> References: <20230111010836.GA1550875@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jan 11, 2023 at 05:20:38PM +1300, Thomas Munro wrote: > Is the problem here that SIGCHLD is processed ... > > PG_SETMASK(&UnBlockSig); <--- here? > > selres = select(nSockets, &rmask, NULL, NULL, &timeout); > > Meanwhile the SIGCHLD handler code says: > > * Was it the wal receiver? If exit status is zero (normal) or one > * (FATAL exit), we assume everything is all right just like normal > * backends. (If we need a new wal receiver, we'll start one at the > * next iteration of the postmaster's main loop.) > > ... which is true, but that won't be reached for a while in this case > if the timeout has already been set to 60s. Your patch makes that > 100ms, in that case, a time delay that by now attracts my attention > like a red rag to a bull (I don't know why you didn't make it 0). I think this is right. At the very least, it seems consistent with my observations. > I'm not sure, but if I got that right, then I think the whole problem > might automatically go away with CF #4032. The SIGCHLD processing > code will run not when signals are unblocked before select() (that is > gone), but instead *after* the event loop wakes up with WL_LATCH_SET, > and runs the handler code in the regular user context before dropping > through to the rest of the main loop. Yeah, with those patches, the problem goes away. IIUC the key part is that the postmaster's latch gets set when SIGCHLD is received, so even if SIGUSR1 and SIGCHLD are processed out of order, WalReceiverPID gets cleared and we try to restart it shortly thereafter. I find this much easier to reason about. I'll go ahead and withdraw this patch from the commitfest. Thanks for chiming in. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com