Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Space required for VACUUM FULL table

From the PostgreSQL 10.4 manual regarding a full vacuum:

Note that they also temporarily use extra disk space approximately equal to the size of the table, since the old copies of the table and indexes can't be released until the new ones are complete

I've read in this in many different places and phrased in a variety of ways. Some indicating that the space required is at most equal to the size of the vacuumed table. Hinting that it may only require enough space to store the resulting vacuumed table, i.e. of size in the range [0-size_of_original_table], depending on how many dead rows are in the table.

My question is: Will doing a full vacuum of a table always require a space equal to the original table size or is it dependent on the number of live rows in the table?

like image 206
Thrasi Avatar asked Jul 16 '18 12:07

Thrasi


People also ask

How much disk space do I need to complete a vacuum?

Then you must have at least 2GB of extra space on your disk, in order to complete the vacuum successfully. Because VACUUM FULL will create a new copy of the table, excluding the dead rows and then remove the existing tables.

What is the difference between vacuum full and normal vacuum?

When you run VACUUM FULL on a table, that table is locked for the duration of the operation, so nothing else can work with the table. VACUUM FULL is much slower than a normal VACUUM, so the table may be unavailable for a while.

Why should I use vacuum full in SQL Server?

Because VACUUM FULL will create a new copy of the table, excluding the dead rows and then remove the existing tables. Recommended because if the largest table contains only live rows you need that much space.

Do I need to close the connection between table and vacuum?

You don't need to close existing connections. One thing to be aware of though, is that moving the table and the vacuum full will themselves need to wait for an exclusive lock first! First, you obviously need some additional storage.


1 Answers

The additional space required by VACUUM (FULL) depends on the number of live rows in the table.

What happens during VACUUM (FULL) is that a new copy of the table is written. All live tuples (= row versions) and the dead tuples that cannot be removed yet will be written to this new copy.

When the transaction finishes, the old copy will be removed.

like image 171
Laurenz Albe Avatar answered Sep 18 '22 19:09

Laurenz Albe