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 1pvpEm-0006FO-9D for pgsql-general@arkaria.postgresql.org; Mon, 08 May 2023 01:00:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pvpEl-0008TQ-6Z for pgsql-general@arkaria.postgresql.org; Mon, 08 May 2023 01:00:23 +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 1pvpEk-0008TG-SS for pgsql-general@lists.postgresql.org; Mon, 08 May 2023 01:00:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pvpEi-00178T-DG for pgsql-general@lists.postgresql.org; Mon, 08 May 2023 01:00:21 +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 34810Ht0209711; Sun, 7 May 2023 21:00:18 -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: <183988.1683494734@sss.pgh.pa.us> Comments: In-reply-to "Michael P. McDonnell" message dated "Sun, 07 May 2023 18:42:21 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <209709.1683507617.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Sun, 07 May 2023 21:00:17 -0400 Message-ID: <209710.1683507617@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Michael P. McDonnell" writes: > On Sun, May 7, 2023 at 4:25 PM Tom Lane wrote: >> Perhaps an "ANALYZE table_b" in between would help. > Okay - that worked. > How did you know that would work? That's incredible. Well, I guessed ;-) ... but it was a well-educated guess. The symptoms sounded like you were getting a bad plan choice for the second query, which is unsurprising if you populate a table from empty and don't give auto-analyze enough time to collect some statistics behind your back. As a solution going forward, I'd recommend adding the ANALYZE as the last step in the table-populating procedure. regards, tom lane