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.94.2) (envelope-from ) id 1sNk4E-00AM08-NA for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Jun 2024 02:13:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sNk3C-00BJDH-BY for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Jun 2024 02:12:22 +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.94.2) (envelope-from ) id 1sNk3B-00BJD8-QT for pgsql-hackers@lists.postgresql.org; Sun, 30 Jun 2024 02:12:22 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sNk35-003nCB-2T for pgsql-hackers@lists.postgresql.org; Sun, 30 Jun 2024 02:12:20 +0000 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3c9cc681e4fso1008268b6e.0 for ; Sat, 29 Jun 2024 19:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1719713534; x=1720318334; darn=lists.postgresql.org; h=user-agent: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=SrYJ8VYlKx+gD/YkMZGXuNLZojT0aXRh2y2JAjfxzDs=; b=UY1YArb/Qgqeczn6V11vxx0oF+fuj9hS6mo6FM9xeHLUfrlIettr496Xt2zr1mjc+p XBL3u0wAQE7QgRb+ZhzYg2CVzXDbMaQ1vpXStQdUT8l2yXSRp/qmsbYySeYJscO9td+X xYowueMQWm4m9LPQJQarUThLb5SdnDoAWk51g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719713534; x=1720318334; h=user-agent: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=SrYJ8VYlKx+gD/YkMZGXuNLZojT0aXRh2y2JAjfxzDs=; b=B4AfqfAsvbF+ejFKNpeyP6ZA0c3mwSsdCYq0Aizxkv+rERyzAn2kM7STWrMHij44G1 l4DHspmiAAxFXMWKjeZXDS3qSXYZNvMYwM+JUIVeWKYya4vRdVCvbfBUEsO+S8x5QQzn LQKJsBJB4pvrhT55xVfdlIlgB7pt1Bj7O4PvnZnYSvnMmU5VKFBPL0TwRMyWq8ldltCs iXGoNc9IPl7zIFGyP7nExtldWGa3L9+dVOZ4XRMw3kn6Rb0Q33gdpqF1N8dWX7Ejyi8K CCb7Mpj+zpAWb3Mlx+JKkd2R8viaxbvdF/U4vAftDGSHvf9qXHEk0JxWl9MXF9v8Ened TZNA== X-Forwarded-Encrypted: i=1; AJvYcCV/P39vjtLLZkNpE0OHprsKS05fPbMnuNthgxO1ffngy08eLHellbI/8hIDSnlnMYuKec58UsLgxbTroOgANpICqWGj6OIoR/SHYjpSN83TE7uH X-Gm-Message-State: AOJu0YzVGRZD1eoGO8lenie4RP+DyerX8Ifym+W6q2vF2A18EwHwpbYA XARMeyTXW7QLv2XS0+SbVm6g+W/9L0EO3hxT4aYC9ZZivmrNp8kh5xFIPaem62G0yysL4YEx/FE = X-Google-Smtp-Source: AGHT+IFj5qjye+Pg/Brnmp0pBX2TbwUgrrcjI/mpuJ9xjtSyuRInuwRRKZ3BbGf9ef0gkGQFpJU+8w== X-Received: by 2002:a05:6808:3021:b0:3d5:2e2f:bf9 with SMTP id 5614622812f47-3d6b39a17c2mr3774095b6e.30.1719713533936; Sat, 29 Jun 2024 19:12:13 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3d62f9b8d32sm863936b6e.10.2024.06.29.19.12.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Jun 2024 19:12:13 -0700 (PDT) Date: Sat, 29 Jun 2024 19:12:11 -0700 From: Noah Misch To: Kyotaro Horiguchi Cc: michael@paquier.xyz, robertmhaas@gmail.com, kuroda.hayato@fujitsu.com, shlok.kyal.oss@gmail.com, pgsql-hackers@lists.postgresql.org, tgl@sss.pgh.pa.us Subject: Re: pg_ctl start may return 0 even if the postmaster has been already started on Windows Message-ID: <20240630021211.f3.nmisch@google.com> References: <20240606.164500.1165061072372246513.horikyota.ntt@gmail.com> <20240606.171515.1237539015915565828.horikyota.ntt@gmail.com> <20240606.172146.1104070889615683903.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240606.172146.1104070889615683903.horikyota.ntt@gmail.com> User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jun 06, 2024 at 05:21:46PM +0900, Kyotaro Horiguchi wrote: > At Thu, 06 Jun 2024 17:15:15 +0900 (JST), Kyotaro Horiguchi wrote in > > By the way, the need to shift by 2 seconds to tolerate clock skew > > suggests that the current launcher-postmaster association mechanism is > > somewhat unreliable. Couldn't we add a command line option to > > postmaster to explicitly pass a unique identifier (say, pid itself) of > > the launcher? If it is not specified, the number should be the PID of > > the immediate parent process. > > No. The combination of pg_ctl's pid and timestamp, to avoid false > matching during reboot. > > > This change avoids the need for the special treatment for Windows. Regarding your "unique identifier" idea, pg_ctl could generate an 8-byte random value for the postmaster to write to postmaster.pid. That would be enough for wait_for_postmaster_start() to ignore PIDs and achieve its mission without OS-specific code. Commits 9886744 and b83747a added /D to two %comspec% callers. I gather they arose to make particular cmd.exe invocations have just one child. However, http://postgr.es/m/20240111.173322.1809044112677090191.horikyota.ntt@gmail.com reports multiple children remain possible. v17 is currently in a weird state where most Windows subprocess invocation routes through pgwin32_system() and does not add /D, while these two callers add /D. I suspect we should either (1) prepend /D in pgwin32_system() and other %comspec% usage or (2) revert prepending it in the callers from this thread's commits. While "Software\Microsoft\Command Processor\AutoRun" is hard to use without breaking things, it's not PostgreSQL's job to second-guess the user in that respect. Hence, I lean toward (2). What do you think?