From: Tom Lane Date: Thu, 27 May 2004 03:30:11 +0000 (+0000) Subject: Recommend ALTER TABLE ... TYPE as the best way to reclaim space occupied by deleted... X-Git-Tag: REL8_0_0BETA1~512 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c792cbcc2680474da3d4e68edfaf805d5f158e4a;p=postgresql Recommend ALTER TABLE ... TYPE as the best way to reclaim space occupied by deleted columns. The old method involving UPDATE and VACUUM FULL will be considerably less efficient. --- diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 6119a15062..e86712e26b 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -1,5 +1,5 @@ @@ -399,17 +399,26 @@ where action is one of: The DROP COLUMN form does not physically remove the column, but simply makes it invisible to SQL operations. Subsequent - insert and update operations in the table will store a null value for the column. - Thus, dropping a column is quick but it will not immediately reduce the - on-disk size of your table, as the space occupied + insert and update operations in the table will store a null value for the + column. Thus, dropping a column is quick but it will not immediately + reduce the on-disk size of your table, as the space occupied by the dropped column is not reclaimed. The space will be reclaimed over time as existing rows are updated. - To reclaim the space at once, do a dummy UPDATE of all rows - and then vacuum, as in: + + + + The fact that ALTER TYPE requires rewriting the whole table + is sometimes an advantage, because the rewriting process eliminates + any dead space in the table. For example, to reclaim the space occupied + by a dropped column immediately, the fastest way is -UPDATE table SET col = col; -VACUUM FULL table; +ALTER TABLE table ALTER COLUMN anycol TYPE anytype; + where anycol is any remaining table column and + anytype is the same type that column already has. + This results in no semantically-visible change in the table, + but the command forces rewriting, which gets rid of no-longer-useful + data.