Re: Dropping column from big table

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: sud <suds1434(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Dropping column from big table
Date: 2024-07-10 21:22:40
Message-ID: f519a562-667c-4a96-9844-a2aaa42928b3@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 7/10/24 13:13, sud wrote:
> Hi All,
> It's postgres database version 15.4. We have a table which is daily and
> is approx. ~2TB in size having a total ~90 partitions. We have a
> requirement to drop columns and add new columns to this table.
>
> I Want to understand, If this can be done online? what is the fastest
> way to drop/add columns from such a big table and what will be the
> consequence of this in regards to vacuum, post this activity? Or if any
> other issues we may face post this?
>
> Regards
> Sud

https://www.postgresql.org/docs/current/sql-altertable.html

"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 by the dropped column
is not reclaimed. The space will be reclaimed over time as existing rows
are updated.

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.
"

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dimitrios Apostolou 2024-07-11 01:19:16 Query on partitioned table needs memory n_partitions * work_mem
Previous Message Juan Rodrigo Alejandro Burgos Mella 2024-07-10 20:37:01 Re: can stored procedures with computational sql queries improve API performance?