0

According to the docs, after deleting rows in postgresql, they remain in a dead state, hence the need to periodically vacuum to reclaim this space. Does this also apply to row width when removing columns from tables, or is that space forever allocated?

terpak
  • 1,131
  • 3
  • 17
  • 35

1 Answers1

1

The answer is yes - the space is reclaimed.

From the documentation about VACUUM (bold emphasis mine):

it writes a new copy of the table and doesn't release the old copy until the operation is complete

And from the notes in page about ALTER TABLE:

To force immediate reclamation of space occupied by a dropped column, you can execute one of the forms of ALTER TABLE that performs a rewrite of the whole table. This results in reconstructing each row with the dropped column replaced by a null value.

and one more:

depending on the parameter you might need to rewrite the table to get the desired effects. That can be done with VACUUM FULL, CLUSTER or one of the forms of ALTER TABLE that forces a table rewrite.

Kamil Gosciminski
  • 16,547
  • 8
  • 49
  • 72