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 1hNlEZ-0000mY-Uh for pgsql-general@arkaria.postgresql.org; Mon, 06 May 2019 21:33:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hNlEX-00089Z-48 for pgsql-general@arkaria.postgresql.org; Mon, 06 May 2019 21:33:13 +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 1hNlEW-000883-PE; Mon, 06 May 2019 21:33:12 +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 1hNlEU-0000Tl-0U; Mon, 06 May 2019 21:33:12 +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 x46LX6Xv015878; Mon, 6 May 2019 17:33:06 -0400 From: Tom Lane To: neeraj kumar cc: pgsql-admin@postgresql.org, pgsql-general@postgresql.org Subject: Re: Query on pg_stat_activity table got stuck In-reply-to: References: Comments: In-reply-to neeraj kumar message dated "Mon, 06 May 2019 11:24:31 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <15876.1557178386.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 06 May 2019 17:33:06 -0400 Message-ID: <15877.1557178386@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk neeraj kumar writes: > We are using PG 10.6. We have one cron job that queries pg_stat_activity > table to find out how many queries are running longer than X minutes and > generate metrics. > Query look like this : > SELECT * FROM pg_stat_activity WHERE state=3D'active' > After some days, this query get stuck and doesn't finish. We tried to ru= n > this query manually and same result. > We looked into pg_locks table and there this query is not blocked on any > lock : > https://justpaste.it/48rpe Interesting. Can you get a stack trace to show where in the code it's stuck? https://wiki.postgresql.org/wiki/Generating_a_stack_trace_of_a_PostgreSQL_= backend regards, tom lane