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 1j1tkD-00066M-MO for pgsql-general@arkaria.postgresql.org; Wed, 12 Feb 2020 15:16:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j1tkC-0006Mz-0i for pgsql-general@arkaria.postgresql.org; Wed, 12 Feb 2020 15:16:04 +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 1j1tkB-0006Ms-NC for pgsql-general@lists.postgresql.org; Wed, 12 Feb 2020 15:16:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j1tk9-0002NL-2Y for pgsql-general@postgresql.org; Wed, 12 Feb 2020 15:16:03 +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 01CFFxuF023752; Wed, 12 Feb 2020 10:15:59 -0500 From: Tom Lane To: Tim Kane cc: PostgreSQL mailing lists Subject: Re: Avoiding out of date statistics / planner In-reply-to: References: Comments: In-reply-to Tim Kane message dated "Wed, 12 Feb 2020 09:06:13 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <23750.1581520559.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Wed, 12 Feb 2020 10:15:59 -0500 Message-ID: <23751.1581520559@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tim Kane writes: > Every now and again, I will encounter an unexplained long-running query. > It’s a head scratcher moment, because this query that is still running for > 20 minutes (not blocking) can be run independently in about 500ms Without some kind of context (like, have you been doing something to the table(s) involved that would drastically change their statistics) it's hard to comment on this. It's not obvious from the info provided that this is a bad-plan issue rather than something else. > On the application side, we can explicitly issue a VACUUM ANALYZE after > each bulk operation - and often that is precisely what happens.. > But - I am keenly aware that this cannot be performed within a transaction. Plain ANALYZE can be, and that's all you need if the problem is to update stats. regards, tom lane