Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHIi1-0002I1-Km for pgsql-general@arkaria.postgresql.org; Wed, 22 Nov 2017 00:16:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHIi0-0005kJ-VA for pgsql-general@arkaria.postgresql.org; Wed, 22 Nov 2017 00:16:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eHIi0-0005iz-P9 for pgsql-general@lists.postgresql.org; Wed, 22 Nov 2017 00:16:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eHIhw-0003Xo-Tq for pgsql-general@postgresql.org; Wed, 22 Nov 2017 00:16:08 +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 vAM0G0dZ008342; Tue, 21 Nov 2017 19:16:00 -0500 From: Tom Lane cc: andres@anarazel.de (Andres Freund), Justin Pryzby , pgsql-general@postgresql.org Subject: Re: backends stuck in "startup" In-reply-to: <7806.1511308921@sss.pgh.pa.us> References: <20171121230926.GA17194@telsasoft.com> <6177.1511306476@sss.pgh.pa.us> <20171121234558.p7rtwkasqfjvpft4@alap3.anarazel.de> <7332.1511308205@sss.pgh.pa.us> <20171121235239.5ssxkvmfwvhxavsm@alap3.anarazel.de> <7806.1511308921@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 21 Nov 2017 19:02:01 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8340.1511309760.1@sss.pgh.pa.us> Date: Tue, 21 Nov 2017 19:16:00 -0500 Message-ID: <8341.1511309760@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > ... Maybe we need > to take a closer look at where LWLocks devolve to blocking on the process > semaphore and see if there's any implicit assumptions about barriers there. Like, say, here: for (;;) { PGSemaphoreLock(proc->sem); if (!proc->lwWaiting) break; extraWaits++; } which is exactly where Justin's backend is stuck. Without a read barrier after the PGSemaphoreLock, it seems possible that we might not see our lwWaiting as cleared yet, causing the loop to go around an extra time and wait for a sema wakeup that will never come. Then, we are holding the lock but are blocked anyway, and everyone else who wants that same lock will queue up behind us. regards, tom lane