public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Scot Kreienkamp <[email protected]>
Cc: pgsql-generallists.postgresql.org <[email protected]>
Subject: Re: vacuum analyze query performance - help me understand
Date: Tue, 19 Aug 2025 14:19:56 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <SJ0PR15MB524590D2BECF3283CDCE39289A30A@SJ0PR15MB5245.namprd15.prod.outlook.com>
References: <a2cd8084-b93e-4da0-8999-569a6e58ef6b.8f62f83c-ab51-428e-98d1-ab1abb243a49.f9527220-afca-46a5-9ff9-6943b4d51eeb@emailsignatures365.codetwo.com>
	<a2cd8084-b93e-4da0-8999-569a6e58ef6b.b1460fbe-55a2-4060-995f-39f4e2f3c7f9.62e1aa37-6482-4ce2-8283-21c365f4f47c@emailsignatures365.codetwo.com>
	<SJ0PR15MB524590D2BECF3283CDCE39289A30A@SJ0PR15MB5245.namprd15.prod.outlook.com>

Scot Kreienkamp <[email protected]> writes:
> That command should vacuum analyze all tables in all databases, and it was proven that it worked as the last vacuum and analyze dates on the tables 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 query 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 same query again, which performed exponentially better.    I verified by comparing before and after explains that the query plan did not change between runs of the query, the only changes were stats like cost, rows, width, time, 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






view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: vacuum analyze query performance - help me understand
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox