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 1nAdXd-0001IF-E4 for pgsql-committers@arkaria.postgresql.org; Thu, 20 Jan 2022 19:56:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nAdXb-0008IG-85 for pgsql-committers@arkaria.postgresql.org; Thu, 20 Jan 2022 19:56:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAdXb-0008I7-11 for pgsql-committers@lists.postgresql.org; Thu, 20 Jan 2022 19:56:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAdXY-0007dX-PR for pgsql-committers@lists.postgresql.org; Thu, 20 Jan 2022 19:56:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 20KJu75n926840; Thu, 20 Jan 2022 14:56:07 -0500 From: Tom Lane To: Andres Freund cc: Noah Misch , Thomas Munro , pgsql-committers Subject: Re: pgsql: TAP tests: check for postmaster.pid anyway when "pg_ctl start" f In-reply-to: <20220120192736.msyesvdlljn6tptw@alap3.anarazel.de> References: <855583.1642687119@sss.pgh.pa.us> <867290.1642689136@sss.pgh.pa.us> <20220120192736.msyesvdlljn6tptw@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Thu, 20 Jan 2022 11:27:36 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <926838.1642708567.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 20 Jan 2022 14:56:07 -0500 Message-ID: <926839.1642708567@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > IOW, the test doesn't actually quite seem to be working in the "local" c= ase? > Hence not seeing the problem of picking up some wrong pid. It looks like there are two different failure cases: 1. The symptom shown by skink: # pg_ctl start failed; logfile: ... 2022-01-20 12:36:22.021 UTC [4023581][postmaster][:0] FATAL: pre-existing= shared memory block (key 16253309, ID 1602617349) is still in use 2022-01-20 12:36:22.021 UTC [4023581][postmaster][:0] HINT: Terminate any= old server processes associated with data directory "/mnt/resource/bf/bui= ld/skink-master/HEAD/pgsql.build/src/test/recovery/tmp_check/t_017_shm_gna= t_data/pgdata". I can reproduce this locally by using a valgrind wrapper around the postmaster. What is evidently happening is that some postmaster child is slow to exit after the postmaster is kill -9'd (thanks to being valgrind'd) and so the would-be new postmaster sees the shmem block as still active. 2. The symptom shown on Noah's AIX flotilla: # pg_ctl start failed; logfile: ... 2022-01-20 03:08:56.200 UTC [11796728:1] FATAL: lock file "postmaster.pid= " already exists 2022-01-20 03:08:56.200 UTC [11796728:2] HINT: Is another postmaster (PID= 6750300) running in data directory "/home/nm/farm/xlc64/HEAD/pgsql.build/= src/test/recovery/tmp_check/t_017_shm_gnat_data/pgdata"? Looking at the code in miscinit.c that emits that message, it seems that kill(6750300, 0) must have succeeded, even though nontrivial time has passed since we did the kill -9. Alternatively, AIX returned some errno other than the two we ignore --- but I checked its manpages and it alleges just the same set of error conditions as Linux. The first of these scenarios could be dealt with easily if we make Cluster::start validate the PID it gets out of the pidfile. The second one seems problematic though: if the killed postmaster is not-dead-yet when the replacement postmaster looks, it might still be that way when Cluster::start checks, a few microseconds later, so that we'd "validate" a PID that's not going to be around much longer. What I'm thinking of doing is inventing a "soft_stop" variant of Cluster::stop that won't complain if pg_ctl stop fails, and then having 017_shm's poll_start() call that before retrying the start call. In this way, if we did manage to start a postmaster then we'll shut it down before trying again, while if we didn't successfully start one then soft_stop will end with _pid unset, allowing Cluster::start to succeed. It seems like it'd also be a good idea if the END block used soft_stop instead of regular stop. As is, if we have multiple postmasters and the first one gives us trouble (say it's dead already), I think we'll likely fail to stop the rest. Not sure what happens if we BAIL_OUT from an END block, but it seems unlikely to be good. regards, tom lane