Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to reindex after vacuum full on Postgres 9.4

I am using Postgres 9.4.

I just ran vacuum full. I read about the differences between vacuum and vacuum full and considered a lot if I should run vacuum or vacuum full. As far as I can say, I required vacuum full and my db size came down from 48 GB to 24 GB.

Would the old indexes would have become obsolete after vacuum full and do I need to run reindex?

I ran "vacuum full verbose analyze", so analyze is done along with vacuum full.

I read at several places that for Postgres > 9.0, I don't need reindex after vacuum full, but I want to be sure that it is the case.

like image 989
Akshar Raaj Avatar asked Jun 23 '15 17:06

Akshar Raaj


People also ask

Does vacuum full reindex?

A full vacuum doesn't perform a reindex for interleaved tables. To reindex interleaved tables followed by a full vacuum, use the VACUUM REINDEX option. By default, VACUUM FULL skips the sort phase for any table that is already at least 95 percent sorted.

What is difference between vacuum and vacuum full in PostgreSQL?

The biggest difference between Vacuum Full and Vacuum is that Vacuum Full physically deletes dead tuples and re-releases the released space to the operating system, so after vacuum full, the size of the table will be reduced to the actual space size.

What is vacuum full in PostgreSQL?

VACUUM FULL rewrites the entire contents of the table into a new disk file with no extra space, allowing unused space to be returned to the operating system. This form is much slower and requires an ACCESS EXCLUSIVE lock on each table while it is being processed.


1 Answers

A REINDEX immediately after a VACUUM FULL is useless because VACUUM FULL itself rebuilds the indexes.

This is mentioned in the 9.4 documentation in Recovering Disk Space :

...to reclaim the excess disk space it occupies, you will need to use VACUUM FULL, or alternatively CLUSTER or one of the table-rewriting variants of ALTER TABLE. These commands rewrite an entire new copy of the table and build new indexes for it.

You are correct that this was not the case before version 9.0, which had VACUUM FULL reimplemented differently.

Up to version 8.4, the reference doc for VACUUM mentioned the need to reindex:

The FULL option does not shrink indexes; a periodic REINDEX is still recommended. In fact, it is often faster to drop all indexes, VACUUM FULL, and recreate the indexes.

But this caveat is now obsolete.

like image 196
Daniel Vérité Avatar answered Sep 22 '22 19:09

Daniel Vérité