HiveBrain v1.2.0
Get Started
← Back to all entries
gotchasqlMinor

What is the real difference between vacuum and vacuum analyze on Postgresql?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlrealthevacuumanalyzewhatdifferencebetweenand

Problem

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?

Solution

tl;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

Context

StackExchange Database Administrators Q#150784, answer score: 5

Revisions (0)

No revisions yet.