Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c792cbc

Browse files
committed
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.
1 parent 92b0b08 commit c792cbc

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

doc/src/sgml/ref/alter_table.sgml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.69 2004/05/05 04:48:45 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.70 2004/05/27 03:30:11 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -399,17 +399,26 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
399399
<para>
400400
The <literal>DROP COLUMN</literal> form does not physically remove
401401
the column, but simply makes it invisible to SQL operations. Subsequent
402-
insert and update operations in the table will store a null value for the column.
403-
Thus, dropping a column is quick but it will not immediately reduce the
404-
on-disk size of your table, as the space occupied
402+
insert and update operations in the table will store a null value for the
403+
column. Thus, dropping a column is quick but it will not immediately
404+
reduce the on-disk size of your table, as the space occupied
405405
by the dropped column is not reclaimed. The space will be
406406
reclaimed over time as existing rows are updated.
407-
To reclaim the space at once, do a dummy <command>UPDATE</> of all rows
408-
and then vacuum, as in:
407+
</para>
408+
409+
<para>
410+
The fact that <literal>ALTER TYPE</> requires rewriting the whole table
411+
is sometimes an advantage, because the rewriting process eliminates
412+
any dead space in the table. For example, to reclaim the space occupied
413+
by a dropped column immediately, the fastest way is
409414
<programlisting>
410-
UPDATE table SET col = col;
411-
VACUUM FULL table;
415+
ALTER TABLE table ALTER COLUMN anycol TYPE anytype;
412416
</programlisting>
417+
where <literal>anycol</> is any remaining table column and
418+
<literal>anytype</> is the same type that column already has.
419+
This results in no semantically-visible change in the table,
420+
but the command forces rewriting, which gets rid of no-longer-useful
421+
data.
413422
</para>
414423

415424
<para>

0 commit comments

Comments
 (0)