gotchasqlMinor
What is the real difference between vacuum and vacuum analyze on Postgresql?
Viewed 0 times
postgresqlrealthevacuumanalyzewhatdifferencebetweenand
Problem
What is the difference between:
and
I read the
Do I need to run both, or one of them is sufficient?
vacuum;and
vacuum analyze;I read the
postgresql manual, but this is still not clear 100% for me. Do I need to run both, or one of them is sufficient?
Solution
tl;dr running
Because
Analyze is an additional maintenance operation next to vacuum. It is supposed to keep the statistics up to date on the table.
Vacuuming isn't the only periodic maintenance your database needs. You
also need to analyze the database so that the query planner has table
statistics it can use when deciding how to execute a query. Simply
put: Make sure you're running ANALYZE frequently enough, preferably
via autovacuum. And increase the default_statistics_target (in
postgresql.conf) to 100.
More info: https://wiki.postgresql.org/wiki/Introduction_to_VACUUM,_ANALYZE,_EXPLAIN,_and_COUNT
vacuum analyze is sufficientBecause
vacuum analyze is complete superset of vacuum. If you run vacuum analyze you don't need to run vacuum separately. See the discussion on the mailing list archive.Analyze is an additional maintenance operation next to vacuum. It is supposed to keep the statistics up to date on the table.
Vacuuming isn't the only periodic maintenance your database needs. You
also need to analyze the database so that the query planner has table
statistics it can use when deciding how to execute a query. Simply
put: Make sure you're running ANALYZE frequently enough, preferably
via autovacuum. And increase the default_statistics_target (in
postgresql.conf) to 100.
More info: https://wiki.postgresql.org/wiki/Introduction_to_VACUUM,_ANALYZE,_EXPLAIN,_and_COUNT
Context
StackExchange Database Administrators Q#150784, answer score: 5
Revisions (0)
No revisions yet.