VACUUM, VACUUM FULL and ANALYZE: This is very basic and important command of PostgreSQL.
We require to execute this command frequently because MVCC nature of PostgreSQL.
You can visit this article for more on MVCC.
In this post, I am providing very quick and short on this.
VACUUM reclaims storage occupied by dead tuples. In MCVV architecture tuples that are deleted which are not physically removed from their table. It presents in a disk until a VACUUM is done.
If your table frequently update, you require to execute VACUUM periodically.
VACUUM does not require an exclusive lock on the table.
1 VACUUM Table_Name;
Whatever space reclaims by VACUUM that space require to use for next storage because all that space require to use for next storage because all that space is scattered in a disk.
VACUUM FULL rewrites the entire table with data into new space without any extra space and release all scattered space of an old table.
VACUUM FULL requires an exclusive lock on the table, but after VACUUM FULL you will get 30% to 40% better performance of the table.
1 VACUUM FULL Table_Name;
After VACUUM or VACUUM FULL this command is also required to execute.
ANALYZE updates all require statistics used by planner. The Planner is responsible to execute query with the best efficient way.
You can also execute VACUUM ANALYZE for both operations.
12 ANALYZE Table_Name;VACUUM ANALYZE Table_Name;
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.