What is the difference between:
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?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.
Sign up to join this communitytl;dr running vacuum analyze
is sufficient
Because 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