Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHgGE-0003me-HV for pgsql-general@arkaria.postgresql.org; Thu, 23 Nov 2017 01:25:02 +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 1eHgGC-0001qc-8t for pgsql-general@arkaria.postgresql.org; Thu, 23 Nov 2017 01:25:00 +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 1eHgGB-0001qS-UR for pgsql-general@lists.postgresql.org; Thu, 23 Nov 2017 01:25:00 +0000 Received: from mail-io0-x233.google.com ([2607:f8b0:4001:c06::233]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eHgG7-0005h2-7T for pgsql-general@postgresql.org; Thu, 23 Nov 2017 01:24:59 +0000 Received: by mail-io0-x233.google.com with SMTP id u42so25073058ioi.9 for ; Wed, 22 Nov 2017 17:24:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=CS8BUuZ0O19jjoHnMnba+WjMX5bm1rgcR2sbkljRmJ4=; b=kFPrRiWiKJfUUIffq1CjfFmK9OnBAVcwdSCFJo4wW8u8oKx6wW3u9idUc4snN8K0rG 0aUoTYJQElfdYYWhTO3vC2b2u1Kb6okzqK5KX/QTulPBzUgEHePukcbkAWdZiqoiS3XH dFvTnr8I/hleWrZYL7wNWfRCWCdzxl6yEGYDgZKs05YSzOB9jtwU9Vz5iOC6vC1oFX7b pirsPIKNQOOSx129AVxqPiIUqrvY3jKM9I3Io01F9TWP0X6Yu76G7iE3cc1J8gxpCGT1 H/CGuf/kZgAldQwuG1/UJ7zjLlbCcIsXYmjqHEJTyDyPuCowAo/mfUkssbAgg6xi4W50 SLzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=CS8BUuZ0O19jjoHnMnba+WjMX5bm1rgcR2sbkljRmJ4=; b=bF7g4QUltupHkelBceP34XCPmYRgJEMiVOsCa7PprVqViCQSC5FtSuu3UObZn06hdS 7O7Qq5TrW7OeLCokJ7BadFVNmcICobCw2OyQzSbZkOYu0v67jV5Q9F0s9bZQ2Atr56e9 eTb0Dq0lrwx9nkxSe/C4ReyMgHz7BZ9GVzZxA5zV4pH1fljJ3cEq5D1A6w97JXT8JTQ5 dt6XYVRZpRCml2+ovTvwtIlKMcCLIVLPFCTMGBXBmXxoxhZCfZ+i92Hd1Z5J+guJ0TCp RhZ8y0G/QDMqT1hWT+glUtXfawc+odXC/MAYy6vyVnfsQMmF58M9QUUMGaQ9E0rhJrux 1fzA== X-Gm-Message-State: AJaThX5++BHFEr9c233ipOcY+IOPwL1+UlK//n3vp1zG1YJc16s5RgBz qbzfLXHaYvtFY8XUqMW8Y3XdL9bkkbg= X-Google-Smtp-Source: AGs4zMaxEdJxIiqDpqPDrXx2akszS1FnRPKv+2YK84oFunaiZGIxquM7DnX5ZbmWTUtxwHNUJGrrEw== X-Received: by 10.107.136.229 with SMTP id s98mr13026025ioi.294.1511400292374; Wed, 22 Nov 2017 17:24:52 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 23sm2648705itj.15.2017.11.22.17.24.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 17:24:51 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id D3BE780102B; Wed, 22 Nov 2017 19:24:50 -0600 (CST) Date: Wed, 22 Nov 2017 19:24:50 -0600 From: Justin Pryzby To: Tom Lane Cc: Andres Freund , pgsql-general@postgresql.org Subject: Re: backends stuck in "startup" Message-ID: <20171123012450.GC5668@telsasoft.com> References: <20171121230926.GA17194@telsasoft.com> <20171121234027.b4n4jlsfda42qb6r@alap3.anarazel.de> <20171122064702.GQ5668@telsasoft.com> <27867.1511375232@sss.pgh.pa.us> <20171122223117.GB5668@telsasoft.com> <14525.1511397830@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <14525.1511397830@sss.pgh.pa.us> User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Nov 22, 2017 at 07:43:50PM -0500, Tom Lane wrote: > Justin Pryzby writes: > > For starters, I found that PID 27427 has: > > > (gdb) p proc->lwWaiting > > $1 = 0 '\000' > > (gdb) p proc->lwWaitMode > > $2 = 1 '\001' > > To confirm, this is LWLockAcquire's "proc", equal to MyProc? > If so, and if LWLockAcquire is blocked at PGSemaphoreLock, > that sure seems like a smoking gun. Right: (gdb) bt #0 0x0000003f6ee0d930 in ?? () #1 0x00007f19f3400d38 in ?? () #2 0x00000000006a4440 in PGSemaphoreLock (sema=0x7f19f3400d38) at pg_sema.c:310 #3 0x0000000000714495 in LWLockAcquire (lock=0x7f19f3404f80, mode=LW_SHARED) at lwlock.c:1233 #4 0x00000000006f75e5 in BufferAlloc (smgr=0x1f3c368, relpersistence=112 'p', forkNum=MAIN_FORKNUM, blockNum=1, mode=RBM_NORMAL, strategy=0x0, hit=0x7fff6ef1c5af "") at bufmgr.c:1012 #5 ReadBuffer_common (smgr=0x1f3c368, relpersistence=112 'p', forkNum=MAIN_FORKNUM, blockNum=1, mode=RBM_NORMAL, strategy=0x0, hit=0x7fff6ef1c5af "") at bufmgr.c:745 [...] (gdb) up #1 0x00007f19f3400d38 in ?? () (gdb) up #2 0x00000000006a4440 in PGSemaphoreLock (sema=0x7f19f3400d38) at pg_sema.c:310 310 errStatus = sem_wait(PG_SEM_REF(sema)); (gdb) up #3 0x0000000000714495 in LWLockAcquire (lock=0x7f19f3404f80, mode=LW_SHARED) at lwlock.c:1233 1233 PGSemaphoreLock(proc->sem); (gdb) p proc->lwWaiting $1 = 0 '\000' (gdb) p proc->lwWaitMode $2 = 1 '\001' (gdb) p proc $3 = (PGPROC *) 0x7f1a77dba500 (gdb) p MyProc $4 = (PGPROC *) 0x7f1a77dba500 (gdb) p MyProc==proc $5 = 1 I suppose one needs to show that this backend was stuck and not "just happened to start 1ms before gdb connected", which I actually have: postgres 27427 17665 0 16:57 ? 00:00:00 postgres: indigo indigo 207.241.169.248(37226) startup ... postgres 30298 17665 0 17:01 ? 00:00:00 postgres: main main 207.241.169.100(43088) startup ..so that process was in "startup" 3-4 minutes after being forked. > My hypothesis about a missed memory barrier would imply that there's (at > least) one process that's waiting but is not in the lock's wait queue and Do I have to also check the wait queue to verify? Give a hint/pointer please? > > Would you suggest how I can maximize the likelyhood/speed of triggering that ? > > Five years ago, with a report of similar symptoms, you said "You need to hack > > pgbench to suppress the single initialization connection it normally likes to > > make, else the test degenerates to the one-incoming-connection case" > > https://www.postgresql.org/message-id/8896.1337998337%40sss.pgh.pa.us > > I don't think that case was related at all. > > My theory suggests that any contended use of an LWLock is at risk, > in which case just running pgbench with about as many sessions as > you have in the live server ought to be able to trigger it. However, > that doesn't really account for your having observed the problem > only during session startup, Remember, this issue breaks existing sessions, too. After it'd happened a couple times, I made sure to leave a session opened to allow collecting diagnostics (and try to un-stick it), but when it recurred, was unable to even SELECT * FROM pg_locks. Am I right this won't help for lwlocks? ALTER SYSTEM SET log_lock_waits=yes Justin