Question

I have a big table which is suffering from Index bloating because a lot of rows are frequently updated. I'm also in the process of deleting a big number of rows.

What would the correct order of executing the following tasks in order to recover disk space?

  • Vacuum, mark dead tuples as free for database reuse, doesn't return space to system.
  • Vacuum Full, rewrites table reducing table bloat, returns space to system.
  • Reindex, rewrites indexes reducing index bloat, returns space to system.
Was it helpful?

Solution

Since PostgreSQL 9.0 a VACUUM FULL should return disc space optimally (just like CLUSTER does). I quote the release notes for 9.0 from the current manual here:

New implementation of VACUUM FULL. This command now rewrites the entire table and indexes, rather than moving individual rows to compact space. It is substantially faster in most cases, and no longer results in index bloat.

Note that it is not normally necessary or even advisable to run VACUUM FULL. It may slow down UPDATEs if you remove all wiggle room for HOT updates and such from the data pages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top