Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uoQwD-003qKz-L3 for pgsql-general@arkaria.postgresql.org; Tue, 19 Aug 2025 18:20:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uoQwC-00G3CX-VA for pgsql-general@arkaria.postgresql.org; Tue, 19 Aug 2025 18:20:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uoQwC-00G3CO-Jj for pgsql-general@lists.postgresql.org; Tue, 19 Aug 2025 18:20:01 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uoQwA-000hoJ-2k for pgsql-general@lists.postgresql.org; Tue, 19 Aug 2025 18:20:00 +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 57JIJu1x601314; Tue, 19 Aug 2025 14:19:56 -0400 From: Tom Lane To: Scot Kreienkamp cc: "pgsql-generallists.postgresql.org" Subject: Re: vacuum analyze query performance - help me understand In-reply-to: References: Comments: In-reply-to Scot Kreienkamp message dated "Tue, 19 Aug 2025 17:37:16 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <601312.1755627596.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 19 Aug 2025 14:19:56 -0400 Message-ID: <601313.1755627596@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Scot Kreienkamp writes: > That command should vacuum analyze all tables in all databases, and it w= as proven that it worked as the last vacuum and analyze dates on the table= s in all databases are showing dates from 2am today. I take it from this that you have autovacuum turned off and you think a once-a-day manual vacuum run is an adequate replacement? > So here's the problem: We ran a (admittedly poorly written) select quer= y against a subset of tables which performed poorly. Then we ran a vacuum= analyze against just those tables involved in that query, then ran the sa= me query again, which performed exponentially better. I verified by com= paring before and after explains that the query plan did not change betwee= n runs of the query, the only changes were stats like cost, rows, width, t= ime, etc. If the plan didn't change then the stats updates weren't very relevant. I am guessing that the actual problem was that those tables were full of dirty rows, and the VACUUM (not the ANALYZE part) got rid of dead rows, set hint bits on recently-updated rows, and generally did a lot of janitorial work that makes subsequent table scans faster. Turning off autovacuum is an anti-pattern. (Running a PG version that's four years past EOL is also an anti-pattern, but you knew that. Should I ask whether it's at least the final 9.6 minor release?) regards, tom lane