Re: Dropping column from big table

From: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Dropping column from big table
Date: 2024-07-15 14:27:44
Message-ID: 20240715142744.7e7a3wtdfxinochf@hjp.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2024-07-15 13:53:25 +0200, Laurenz Albe wrote:
> On Sun, 2024-07-14 at 00:05 +0200, Peter J. Holzer wrote:
> > On 2024-07-11 10:06:47 +0200, Laurenz Albe wrote:
> > > Dropping a column is fast, but doesn't reclaim the space.
> > > VACUUM won't block anything, but won't reclaim the space.
> > > VACUUM (FULL) will block everything, but will also not reclaim the space.
> > >
> > > You'd need to use a form of ALTER TABLE that rewrites the table,
> > > as indicated in the documentation.
> >
> > Unfortunately the documentation indicates very little. It mentions that
> > the table will be rewritten with
> >
> > * SET ACCESS METHOD
> > * a volatile DEFAULT
> > * changing the type of an existing column (unless binary coercible)
> >
> > All three change something which you probably don't want to change.
>
> Hm, true.
>
> You can always do
>
> UPDATE tab SET id = id;
>
> followed by
>
> VACUUM (FULL) tab;

Yes, that should work. It needs about twice the size of the table in
temporary space, though.

Since the OP wrote that the table is "daily ... and 90 partitions"
(which understand that there is one partition per day and partitions are
kept for 90 days) it might be better to just wait. After 90 days all the
partitions with the obsolete column will be gone.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp(at)hjp(dot)at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2024-07-15 14:35:18 Re: How does this FK constraint error happen?
Previous Message Ron Johnson 2024-07-15 14:04:39 How does this FK constraint error happen?