public inbox for [email protected]help / color / mirror / Atom feed
Dropping column from big table 3+ messages / 2 participants [nested] [flat]
* Dropping column from big table @ 2024-07-10 20:13 sud <[email protected]> 0 siblings, 1 reply; 3+ messages in thread From: sud @ 2024-07-10 20:13 UTC (permalink / raw) To: pgsql-general <[email protected]> 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 ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Dropping column from big table @ 2024-07-10 21:22 Adrian Klaver <[email protected]> parent: sud <[email protected]> 0 siblings, 1 reply; 3+ messages in thread From: Adrian Klaver @ 2024-07-10 21:22 UTC (permalink / raw) To: sud <[email protected]>; pgsql-general <[email protected]> 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 [email protected] ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Dropping column from big table @ 2024-07-11 03:28 sud <[email protected]> parent: Adrian Klaver <[email protected]> 0 siblings, 0 replies; 3+ messages in thread From: sud @ 2024-07-11 03:28 UTC (permalink / raw) To: Adrian Klaver <[email protected]>; +Cc: pgsql-general <[email protected]> On Thu, Jul 11, 2024 at 2:52 AM Adrian Klaver <[email protected]> wrote: > > 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. > " > > Thank you so much. When you said *"you can execute one of the forms of ALTER TABLE that performs a rewrite* *of the whole table."* Does it mean that post "alter table drop column" the vacuum is going to run longer as it will try to clean up all the rows and recreate the new rows? But then how can this be avoidable or made better without impacting the system performance and blocking others? ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2024-07-11 03:28 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2024-07-10 20:13 Dropping column from big table sud <[email protected]> 2024-07-10 21:22 ` Adrian Klaver <[email protected]> 2024-07-11 03:28 ` sud <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox