Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iddMG-0006nl-Um for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Dec 2019 16:55:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iddMF-0005VE-IB for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Dec 2019 16:55:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iddMF-0005Tc-5T for pgsql-bugs@lists.postgresql.org; Sat, 07 Dec 2019 16:55:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iddM8-0002Qv-Kf for pgsql-bugs@lists.postgresql.org; Sat, 07 Dec 2019 16:55:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xB7Gss1O029332; Sat, 7 Dec 2019 11:54:55 -0500 From: Tom Lane To: Alexander Law cc: Amit Kapila , PostgreSQL mailing lists Subject: Re: BUG #16154: pg_ctl restart with a logfile fails sometimes (on Windows) In-reply-to: References: <16154-1ccf0b537b24d5e0@postgresql.org> Comments: In-reply-to Alexander Law message dated "Sat, 07 Dec 2019 19:00:01 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29330.1575737694.1@sss.pgh.pa.us> Date: Sat, 07 Dec 2019 11:54:54 -0500 Message-ID: <29331.1575737694@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alexander Law writes: > What is the reason for the previous shell still accessing logfile? > Is the reason that we don't close it before unlinking the pid file? > We can't close the logfile, as it is opened by CMD, not by the postgres > process. (Postmaster is started by the command "CMD.EXE /C postgres ... >> logfile".) So it is closed by the CMD shell after the postgres process > exits and the postgres can't control this (as a child process). Hmm ... so if we were talking about Unix, a reasonable solution would be to avoid having a separate shell process, either by telling the shell to "exec" the postmaster or by using fork/exec directly with no shell. A 99% solution would be to use "&" so that the shell doesn't wait around for the postmaster to die. Are any of those ideas tenable on Windows? regards, tom lane