Re: vacuum analyze query performance - help me understand - Mailing list pgsql-general

From Tom Lane
Subject Re: vacuum analyze query performance - help me understand
Date
Msg-id 601313.1755627596@sss.pgh.pa.us
Whole thread Raw
In response to vacuum analyze query performance - help me understand  (Scot Kreienkamp <Scot.Kreienkamp@la-z-boy.com>)
Responses RE: vacuum analyze query performance - help me understand
List pgsql-general
Scot Kreienkamp <Scot.Kreienkamp@la-z-boy.com> writes:
> That command should vacuum analyze all tables in all databases, and it was proven that it worked as the last vacuum
andanalyze 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,
whichperformed exponentially better.    I verified by comparing before and after explains that the query plan did not
changebetween 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



pgsql-general by date:

Previous
From: Scot Kreienkamp
Date:
Subject: vacuum analyze query performance - help me understand
Next
From: Adrian Klaver
Date:
Subject: Re: Streaming replica hangs periodically for ~ 1 second - how to diagnose/debug