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 1hOpDy-0003zl-Lh for pgsql-general@arkaria.postgresql.org; Thu, 09 May 2019 20:01:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hOpDv-0002yR-Ox for pgsql-general@arkaria.postgresql.org; Thu, 09 May 2019 20:00:59 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hOpDv-0002yG-EJ; Thu, 09 May 2019 20:00:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hOpDt-0000rr-80; Thu, 09 May 2019 20:00:59 +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 x49K0qUx030688; Thu, 9 May 2019 16:00:52 -0400 From: Tom Lane To: Jeremy Schneider cc: neeraj kumar , pgsql-admin@postgresql.org, pgsql-general@postgresql.org Subject: Re: Query on pg_stat_activity table got stuck In-reply-to: References: <15877.1557178386@sss.pgh.pa.us> <21502.1557339176@sss.pgh.pa.us> <29660.1557352732@sss.pgh.pa.us> Comments: In-reply-to Jeremy Schneider message dated "Thu, 09 May 2019 12:46:32 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30686.1557432052.1@sss.pgh.pa.us> Date: Thu, 09 May 2019 16:00:52 -0400 Message-ID: <30687.1557432052@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jeremy Schneider writes: > Seems to me that at a minimum, this loop shouldn't go on forever. Even > having an arbitrary, crazy high, hard-coded number of attempts before > failure (like a million) would be better than spinning on the CPU > forever - which is what we are seeing. I don't think it's the readers' fault. The problem is that the writer is violating the protocol. If we put an upper limit on the number of spin cycles on the reader side, we'll just be creating a new failure mode when a writer gets swapped out at the wrong moment. IMO we need to (a) get the failure-prone code out of the critical section, and then (b) fix the pgstat_increment_changecount macros so that the critical sections around these shmem changes really are critical sections (ie bump CritSectionCount). That way, if somebody makes the same mistake again, at least there'll be a pretty obvious failure rather than a lot of stuck readers. regards, tom lane