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 1m300x-0003M3-AL for pgsql-general@arkaria.postgresql.org; Mon, 12 Jul 2021 17:46:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m300w-0001iw-9z for pgsql-general@arkaria.postgresql.org; Mon, 12 Jul 2021 17:46:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m300w-0001iA-1F for pgsql-general@lists.postgresql.org; Mon, 12 Jul 2021 17:46:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m300p-0001bG-Uy for pgsql-general@lists.postgresql.org; Mon, 12 Jul 2021 17:46:41 +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 16CHkUg52985640; Mon, 12 Jul 2021 13:46:31 -0400 From: Tom Lane To: Jurrie Overgoor cc: pgsql-general , Vijaykumar Jain Subject: Re: How to debug a connection that's "active" but hanging? In-reply-to: References: Comments: In-reply-to Jurrie Overgoor message dated "Mon, 12 Jul 2021 19:37:30 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2985638.1626111990.1@sss.pgh.pa.us> Date: Mon, 12 Jul 2021 13:46:30 -0400 Message-ID: <2985639.1626111990@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jurrie Overgoor writes: > Hi Vijaykumar, thanks for replying. Yes, this is reproducible. About 50% > of the times, my connection is hanging. It's always on the same query, > which I shared in the previous post. The backtraces you captured look like the query is not "hung", it's just computing away. A plausible interpretation of the facts you've given is that the query's plan is unstable, and sometimes the server is choosing a plan that takes much longer to run than other times. Ordinarily I'd suggest that the auto_explain extension might help you debug that, but I think it only works on queries that do eventually complete. You might need to investigate by altering your application to capture "EXPLAIN ..." output just before the troublesome query, so you can see if it gets a different plan in the slow cases. regards, tom lane