|
1 | 1 | <!--
|
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 $ |
3 | 3 | PostgreSQL documentation
|
4 | 4 | -->
|
5 | 5 |
|
@@ -399,17 +399,26 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
|
399 | 399 | <para>
|
400 | 400 | The <literal>DROP COLUMN</literal> form does not physically remove
|
401 | 401 | 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 |
405 | 405 | by the dropped column is not reclaimed. The space will be
|
406 | 406 | 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 |
409 | 414 | <programlisting>
|
410 |
| -UPDATE table SET col = col; |
411 |
| -VACUUM FULL table; |
| 415 | +ALTER TABLE table ALTER COLUMN anycol TYPE anytype; |
412 | 416 | </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. |
413 | 422 | </para>
|
414 | 423 |
|
415 | 424 | <para>
|
|
0 commit comments