public inbox for [email protected]help / color / mirror / Atom feed
Re: vacuum analyze query performance - help me understand 3+ messages / 3 participants [nested] [flat]
* Re: vacuum analyze query performance - help me understand @ 2025-08-19 18:19 Tom Lane <[email protected]> 2025-08-19 20:09 ` RE: vacuum analyze query performance - help me understand Scot Kreienkamp <[email protected]> 0 siblings, 1 reply; 3+ messages in thread From: Tom Lane @ 2025-08-19 18:19 UTC (permalink / raw) To: Scot Kreienkamp <[email protected]>; +Cc: pgsql-generallists.postgresql.org <[email protected]> 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 ^ permalink raw reply [nested|flat] 3+ messages in thread
* RE: vacuum analyze query performance - help me understand 2025-08-19 18:19 Re: vacuum analyze query performance - help me understand Tom Lane <[email protected]> @ 2025-08-19 20:09 ` Scot Kreienkamp <[email protected]> 2025-08-20 16:26 ` Re: vacuum analyze query performance - help me understand Greg Sabino Mullane <[email protected]> 0 siblings, 1 reply; 3+ messages in thread From: Scot Kreienkamp @ 2025-08-19 20:09 UTC (permalink / raw) To: Tom Lane <[email protected]>; +Cc: pgsql-generallists.postgresql.org <[email protected]> Hi Tom, 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. [Scot Kreienkamp] I thought dead rows were excluded from backup and the resulting restore? All the janitorial was already done a few hours before by a vacuum analyze, so with no activity there shouldn't have been any to do. That's why I'm still looking for answers. Turning off autovacuum is an anti-pattern. [Scot Kreienkamp] Agreed, that's why it's not disabled. I'm out of date, not clueless. The only time I turn off autovac is during full database restores. Last I knew running a periodic reindex and a daily vac/analyze even with autovac enabled was considered best practice. Is that no longer the case? (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?) [Scot Kreienkamp] It is the final release. I guarantee I'm more irritated that we're still on this version than anyone else on earth. They've been warned, many times and loudly, for much longer than 4 years. All I can do is keep reminding and warning of the consequences, like not being able to get help with problems when they inevitably arise. In the meantime, I still have to support it like a number of people's livelihoods (including mine) depends on it. Because they do. Scot Kreienkamp | Applications Infrastructure Architect | La-Z-Boy Corporate One La-Z-Boy Drive | Monroe, Michigan 48162 | • (734) 384-6403 | | • 1-734-915-1444 | Email: [email protected] This message is intended only for the individual or entity to which it is addressed. It may contain privileged, confidential information which is exempt from disclosure under applicable laws. If you are not the intended recipient, you are strictly prohibited from disseminating or distributing this information (other than to the intended recipient) or copying this information. If you have received this communication in error, please notify us immediately by e-mail or by telephone at the above number. Thank you. Attachments: [application/ms-tnef] winmail.dat (22.3K, 2-winmail.dat) download ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: vacuum analyze query performance - help me understand 2025-08-19 18:19 Re: vacuum analyze query performance - help me understand Tom Lane <[email protected]> 2025-08-19 20:09 ` RE: vacuum analyze query performance - help me understand Scot Kreienkamp <[email protected]> @ 2025-08-20 16:26 ` Greg Sabino Mullane <[email protected]> 0 siblings, 0 replies; 3+ messages in thread From: Greg Sabino Mullane @ 2025-08-20 16:26 UTC (permalink / raw) To: Scot Kreienkamp <[email protected]>; +Cc: Tom Lane <[email protected]>; pgsql-generallists.postgresql.org <[email protected]> Moving forward advice: * Run the query more than once before doing a manual vacuum to rule out caching. * Change your flags for the vacuumdb from --quiet to --verbose and we can see exactly what vacuum has done. Ideally have cron append to a file on disk * Similarly, set log_autovacuum_min_duration to 0 (which logs all autovacuum activity). * As mentioned upthread, use explain (analyze, buffers, settings) for better output * Using the pg_buffercache extension can show you exactly what is in shared buffers (for future debugging) Cheers, Greg -- Crunchy Data - https://www.crunchydata.com Enterprise Postgres Software Products & Tech Support ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2025-08-20 16:26 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2025-08-19 18:19 Re: vacuum analyze query performance - help me understand Tom Lane <[email protected]> 2025-08-19 20:09 ` Scot Kreienkamp <[email protected]> 2025-08-20 16:26 ` Greg Sabino Mullane <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox