I have a table with 200 GB of size occupied by data and 180 GB of size by the 6 indexes on it. It is 30% bloated, so I want to reclaim unwanted space occupied by it. It is clustered on job_id_id
x index.
So to reclaim the space do I need to use cluster
command or vacuum full
command?
-
What is the difference between this two command ?
-
Is
vacuum full
order by some column same ascluster
command? -
Is index recreated in both the commands?
-
In my case which one will be faster?
The version of PostgreSQL database is 9.1
Best Answer
To check what
CLUSTER
does, I took a table fo mine from an earlier experiment which basically contained the first 10 million positive integers. I already deleted some rows and there is an other column as well but these only affect the actual table size, so it is not that interesting.First, having run
VACUUM FULL
on the tablefka
, I took its size:Then let's see the physical order of the data from the very beginning of the table:
Now let's delete some rows:
After this, the reported table size did not change. So let's see now what
CLUSTER
does:After the operation the table size changed from 338 to 296 MB. From the
ctid
column, which describes the physical place of the tuple in the page, you also see that there is no gap where the row matchingid = 5
used to be.As the tuples were reordered, indexes should have been recreated so that they point to the correct places.
So the difference looks to be that
VACUUM FULL
does not order the rows. As far as I know, there is some difference in the mechanism the two commands use but from a practical point of view this seems to be the main (only?) difference.