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 1pvlt5-000575-3S for pgsql-general@arkaria.postgresql.org; Sun, 07 May 2023 21:25:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pvlt3-0007F1-4X for pgsql-general@arkaria.postgresql.org; Sun, 07 May 2023 21:25:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pvlt2-0007Es-Qw for pgsql-general@lists.postgresql.org; Sun, 07 May 2023 21:25:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pvlsv-001CSX-0v for pgsql-general@lists.postgresql.org; Sun, 07 May 2023 21:25:44 +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 347LPYgM183989; Sun, 7 May 2023 17:25:34 -0400 From: Tom Lane To: "Michael P. McDonnell" cc: pgsql-general@lists.postgresql.org Subject: Re: Hung Query with No Locking Issues In-reply-to: References: Comments: In-reply-to "Michael P. McDonnell" message dated "Sun, 07 May 2023 11:53:55 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <183987.1683494734.1@sss.pgh.pa.us> Date: Sun, 07 May 2023 17:25:34 -0400 Message-ID: <183988.1683494734@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Michael P. McDonnell" writes: > I have 2 stored procedures that need to run back to back. It could > convert to a single one - but it's easier from a maintenance perspective to > keep them separated. > The first procedure effectively is > INSERT INTO table_b () SELECT ____ FROM _table_a_; > COMMIT; > Total execution time - about 180s. Nothing in the pg_locks table and > nothing in the pg_stat_activity table suggests anything is hung over. > The second procedure mutates table_b data into table_b_collapsed > INSERT INTO table_c () SELECT _____ FROM _table_b_ JOIN _table_b as b1_ > JOIN _table_b as b2_ JOIN _table_b as b3_, etc...; > COMMIT; > The first time I run my second stored procedure - it hangs for up to 8 > hours. > If I immediately cancel and re-run the second stored procedure it runs in 2 > seconds. Perhaps an "ANALYZE table_b" in between would help. regards, tom lane