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 1lWPEv-0007VS-T4 for pgsql-admin@arkaria.postgresql.org; Tue, 13 Apr 2021 20:02:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lWPEu-0004WF-RX for pgsql-admin@arkaria.postgresql.org; Tue, 13 Apr 2021 20:02:24 +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 1lWPEu-0004W7-K3 for pgsql-admin@lists.postgresql.org; Tue, 13 Apr 2021 20:02:24 +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 1lWPEs-0008Ao-KB for pgsql-admin@lists.postgresql.org; Tue, 13 Apr 2021 20:02:23 +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 13DK2IiP3378154; Tue, 13 Apr 2021 16:02:18 -0400 From: Tom Lane To: Novak Ivan cc: "pgsql-admin@lists.postgresql.org" , =?utf-8?B?S8O8bWluIEFudG9uaW8=?= Subject: Re: Create temp table query hangs In-reply-to: References: Comments: In-reply-to Novak Ivan message dated "Tue, 13 Apr 2021 18:26:02 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3378152.1618344138.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 13 Apr 2021 16:02:18 -0400 Message-ID: <3378153.1618344138@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Novak Ivan writes: > * a query for creating temporary table on target schema is hanging f= orever and we are out of ideas why. Looking at wait_event as well as wait_event_type in pg_stat_activity might give some more clues. > When we try to create a (temporary) table with one statement, and that q= uery takes forever (even after >24h the query is still there). In the Post= gres Database we see three identical active PIDs for the same query (with = same starttimestamp). But we only sent the statement once to the DB. See s= creenshot below. I think this is just a parallelized query with two worker processes. Were the query's source tables freshly created or freshly populated? If so, you might need to issue ANALYZE commands on them before you start the query itself, to make sure the query planner has valid statistics to work with. It's possible that the problem is just a very dumb choice of query plan due to lack of stats. Have you tried comparing EXPLAIN output for this query across the scenarios where it works well and where it doesn't? If it is a bad-plan problem then there'd be obvious differences in the shape of the plan. regards, tom lane