Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wEiKX-004JxN-0f for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Apr 2026 06:42:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wEiKV-0014X1-0A for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Apr 2026 06:41:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wEiKU-0014Ws-1i for pgsql-hackers@lists.postgresql.org; Mon, 20 Apr 2026 06:41:58 +0000 Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wEiKS-00000001sp6-1E6r for pgsql-hackers@postgresql.org; Mon, 20 Apr 2026 06:41:57 +0000 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-7b186dfc1d0so35363697b3.1 for ; Sun, 19 Apr 2026 23:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776667316; cv=none; d=google.com; s=arc-20240605; b=aeibE6vbbF6TyMpFZ562dxnKDfa7FgiZLZNp4HZ+dLv45BAwaMVXuw+7ZfCwfCbGbW K6lQzm/aDd3Zh2KXKKkC1x+CzQbTkQCOTGXG1Me0A0CzwaehsrEe+Ct/sbDp9jYq6SnL TrpdQWsSjcUErD99uoZLGxTMrk35wZxayT7SPgWDnRs0QfDZfTBRnDjxxcBWXF7jiI+o zQnEHApNw8zRdL1WsdSE10cTlYxxgasEh0YoHsc9c5hrWd9KwDBJ7K2thXY3dFV+86SY A8WPiNXtWbfR2hS55nenCehop8GWieQ9cT+zzdVi9Da7Evpn+/mvp9xngujI9957aWfV TzXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=C2Lmh7BcG9+rbQ4kjPzEioBVv16Y5Ltx7IphwzyeTAA=; fh=3GKeX9p1MT4+jbw/1wLC4ubBJ71EOeyzkuYwUxD6LgU=; b=XmJ8j1thL9UHWGjz+hyHf2Tm5UlIJjcsKiKltoLk5UlODuo6B5mbdLf1ab8dQC/54+ rmrm49w26LjwmbCzhU5AvM36BD9Ck4xmrXt/DQ038cql6InS6wkHadv0WCDm1RJppcGE ID3fVrDMAoI+WvryjlINoU8joPqi2I0mxUZ5qmtf+D+1Xep8rBjPHMs/aeuic2LLY5Vl wwqlc36BxIRxNL1kpguYZ9N2Mq9WEFjo5dZMZfWWpFTsT3ykYQE+57WILdWQU86nGQm1 BswRZrP1ghXmK4rTm9bVOWj3c5bQJathplehsVf/Q5rfOx2dpGISkMy2NZ1lN5i97SaB 7Xtw==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776667316; x=1777272116; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=C2Lmh7BcG9+rbQ4kjPzEioBVv16Y5Ltx7IphwzyeTAA=; b=fCRa9qQAakzPDufZKKiOq2bhibxKPqJ1/JDJQJnLToOvHFMvw/bpu60LWK4F/3mv2G cLcWtA1r0UTuILOJE1Ht++MxD1A9WVspz+laYMD6JgPxDDvsNlNx8fQIFX7JuxJSqaa8 SPvQ/HTKuR8CDgv/FoE9sfmNhWl/SjrQUXTKdSFGzE5s8/xKaIS3Lzi4jRH+S12J31bf SCUdGZo4dA9yUXvEcfwEyzHwdYbNB8JmR6BfrJkatXD6j9kt8e6H6IMRwAvqnSJSSl/x 1nqIg9iUqARUrSQ14LfRkgfPImd22x66yoymhmifYgZIfOzfpi1iB0aaxHi5/xMLGRCK iGYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776667316; x=1777272116; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=C2Lmh7BcG9+rbQ4kjPzEioBVv16Y5Ltx7IphwzyeTAA=; b=D2e1xtAEThYJcJO9tiXeIyNGS9hKahqfgVSMTazqnPnz5IMvrq3Ql2o1XOD/ResvO2 qdvVC9w5wncsQONQmqi1R98xL+t0ZJhlPGH0/Q3mrPIxF4PSiQjRxQsCRptPwOWfMO+w d+X2pqasYRYcTrvJG+0MYRtFpdfeLCuAsH7CUBvcc6aOYese4m3BenZbOirf+KK4ytUT kw2mrOVBa6lOUXGjjePzrlNsj2IupKFaFKvySMXzY4kfJWQcAaHdp3unqLxQozKaMrTL bNtDFMp39DVM4WWMNe57DM8NRfNTuH51i3lmhp5UqGDyxnV9Fng5X0sJy9oL4Lm2V5KC ocEw== X-Forwarded-Encrypted: i=1; AFNElJ/AB4iki//vJATXXHy0TTpx7Uwg6TPegLkW2GpSvuc9llTut0BF1PYTb2rCoSpSDyMK8Sxdiddesxor6c7N@postgresql.org X-Gm-Message-State: AOJu0YzncdbhiD6pG3pu39BPt8FnaTKOVcn0ty0A4DDZ0qTfaWlhVdKl 1icXJdLQsaUplNw4PJUP2yU2qBrlvqAsG6DoWT5wvU+dwHILLWp+hicGACwU3s4+s2KVIVXvsFY OmQt9WmNJkE+qAOnueLYBf8/1WUwoPKG2Rn5XKKo= X-Gm-Gg: AeBDiesYhNAzgliaCrp7qRRIPtQezAWJNeHs81cLfwWJgDYpTi7uayR6g3KzsvsAMie patLLEEcEaibFIiZaA9aiw9Lc14A4Q4Albva0cK+jUE8KtLgnznIQ19cP76IWfSojqUF634nsxe i1FotnBwxC5WHrxl8RJH6fnYuix9Q+oUleA6uaiAtaQJaQFX0+I8IWSD3FHDTHdR3loJLKdZHSV kZxY1UZIQE5ZQ84xI4gFOxqiLnti70EySiIbKF2E0rOfuG1pOPugCHrQeSLlB60Ic1oFh+ZY66J HC4eBVhnYY1zp51RL4qgW8IepchA+gTILc2w2RsR/a7324/9Ww== X-Received: by 2002:a05:690c:6e86:b0:7b3:b0a6:2c60 with SMTP id 00721157ae682-7b9ed276d51mr89254397b3.1.1776667316032; Sun, 19 Apr 2026 23:41:56 -0700 (PDT) MIME-Version: 1.0 References: <0f462532-9790-4334-b503-4ee522225820@iki.fi> In-Reply-To: From: Ayush Tiwari Date: Mon, 20 Apr 2026 12:11:45 +0530 X-Gm-Features: AQROBzA7TMvfVNTf_rMRzghg74yuwMN0YaE40yf0qYmgPbDiHVNks06_wNTc4W8 Message-ID: Subject: Re: [PATCH] postmaster: fix stale PM_STARTUP comment To: Michael Paquier Cc: Heikki Linnakangas , pgsql-hackers@postgresql.org, "noah@leadboat.com" Content-Type: multipart/alternative; boundary="00000000000041973f064fde9845" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000041973f064fde9845 Content-Type: text/plain; charset="UTF-8" Hi, Thanks a lot for the review!. On Sat, 18 Apr 2026 at 04:24, Michael Paquier wrote: > On Fri, Apr 17, 2026 at 07:17:18PM +0530, Ayush Tiwari wrote: > > I've attached a patch, please review and let me know your thoughts. > > /* > - * Unexpected exit of startup process (including FATAL exit) > - * during PM_STARTUP is treated as catastrophic. There are no > - * other processes running yet, so we can just exit. > - */ > - if (pmState == PM_STARTUP && > - StartupStatus != STARTUP_SIGNALED && > - !EXIT_STATUS_0(exitstatus)) > > The assumption that only the startup process is running while we are > in a PM_STARTUP state is wrong since 7ff23c6d277d, and this exit code > path has been missed the fact that now the checkpointer and the > bgwriter are started during recovery. So this means a backpatch. > Agreed, this is latent since 7ff23c6d277d (v15). I can prepare a back-branch versions patch for v15..master once the master patch shape is settled > > Removing the assertion is the right move, yes, there are other > children, so again that's an issue with 7ff23c6d277d. I am planning > to double-check the shutdown sequence while switching to > PM_WAIT_BACKENDS under a PM_STARTUP, just note that bgworkers that use > BgWorkerStart_PostmasterStart cannot request a database connection, > meaning that PM_WAIT_BACKENDS should be pointeless, but perhaps it > makes the whole shutdown flow easier to reason about, as you are > suggesting, as making this path more complicated would lead to the > addition of more postmaster states. Making this code simpler, not > more complicated, is always useful. > -- > Michael > Right, I believe at PM_STARTUP the only children we can possibly have are the auxiliary processes (checkpointer, bgwriter, walwriter (if applicable), IO workers) and BgWorkerStart_PostmasterStart bgworkers, none of which should hold backend slots. So, PM_WAIT_BACKENDS is functionally a no-op in this case and we transition straight through to PM_WAIT_DEAD_END. I considered short-circuiting directly to PM_WAIT_DEAD_END from PM_STARTUP, but routing through the same state path the rest of the crash-handling code uses keeps the state machine uniform and avoids a special case in HandleFatalError() / PostmasterStateMachine(). Making the code simpler, as you mentioned. Regards, Ayush --00000000000041973f064fde9845 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,=C2=A0

Thanks a lot for the rev= iew!.

On Sat, 18 Apr 2026 at 04:24, Mic= hael Paquier <michael@paquier.xyz= > wrote:
= On Fri, Apr 17, 2026 at 07:17:18PM +0530, Ayush Tiwari wrote:
> I've attached a patch, please review and let me know your thoughts= .

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/*
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* Unexpected exit of start= up process (including FATAL exit)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* during PM_STARTUP is tre= ated as catastrophic. There are no
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* other processes running = yet, so we can just exit.
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (pmState =3D=3D PM_STARTUP &a= mp;&
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 StartupStatus !=3D= STARTUP_SIGNALED &&
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 !EXIT_STATUS_0(exi= tstatus))

The assumption that only the startup process is running while we are
in a PM_STARTUP state is wrong since 7ff23c6d277d, and this exit code
path has been missed the fact that now the checkpointer and the
bgwriter are started during recovery.=C2=A0 So this means a backpatch.
<= /blockquote>

Agreed, this is latent since 7ff23c6d277d (= v15). I can prepare a back-branch=C2=A0
versions patch for v15..m= aster once the master patch shape is settled
=C2=A0

Removing the assertion is the right move, yes, there are other
children, so again that's an issue with 7ff23c6d277d.=C2=A0 I am planni= ng
to double-check the shutdown sequence while switching to
PM_WAIT_BACKENDS under a PM_STARTUP, just note that bgworkers that use
BgWorkerStart_PostmasterStart cannot request a database connection,
meaning that PM_WAIT_BACKENDS should be pointeless, but perhaps it
makes the whole shutdown flow easier to reason about, as you are
suggesting, as making this path more complicated would lead to the
addition of more postmaster states.=C2=A0 Making this code simpler, not
more complicated, is always useful.
--
Michael

Right, I believe at PM_STARTUP the o= nly children we can possibly have are
the auxiliary processes (checkpointer, bgwriter, walwriter= =C2=A0(if applicable),
none of which should hold= backend slots. So, PM_WAIT_BACKENDS is functionally=C2=A0
a no-op in this case and we transiti= on straight through to=C2=A0
PM_WAIT_DEAD_END.

I considered short-circuiting directl= y to=C2=A0
PM_WAIT_DEAD_END from PM_STARTUP, but routing through = the same=C2=A0
state path the rest of the crash-handling code use= s keeps the state machine=C2=A0
uniform and avoids a special case= in HandleFatalError() / PostmasterStateMachine().=C2=A0
Making t= he code simpler, as you mentioned.

Regards,
Ayush
=
--00000000000041973f064fde9845--