Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTSLW-00GQVf-Dp for pgsql-general@arkaria.postgresql.org; Mon, 15 Jul 2024 20:30:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sTSLT-00D9Lm-Fo for pgsql-general@arkaria.postgresql.org; Mon, 15 Jul 2024 20:30:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTSLT-00D9Ld-1f for pgsql-general@lists.postgresql.org; Mon, 15 Jul 2024 20:30:51 +0000 Received: from mail-vk1-xa33.google.com ([2607:f8b0:4864:20::a33]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sTSLI-002IFK-O0 for pgsql-general@lists.postgresql.org; Mon, 15 Jul 2024 20:30:50 +0000 Received: by mail-vk1-xa33.google.com with SMTP id 71dfb90a1353d-4f2fad3fb8eso2051942e0c.0 for ; Mon, 15 Jul 2024 13:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721075438; x=1721680238; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=SfAFcOpsEWKKzNdGbGiFbAnxGKMzUl+aLp4W8AHT3yY=; b=EIKqldi55yr6sQ9NvAJrmEQu9+J0Dc5bRWONswaXvlf9E02W5bbiOiSP+ZdMUfzJuT 2tVXjZGbTlhy8uVf9zIwSyaodWwzAgYDcXs6CdcCkgryE4muhj9vYTJIF8qsHxLSPDr+ xJTw1XXSqmKfg3PRyxa3wLkHpbu47ZJDMK7u9+QjBbh41Usu/1GsWaZH0lCdMmP5vVRn z7jse9SDCZOwVACKNOegU2Erzh2OwtgPdCJQDbZdy+q6IphTsehIsoOElTeql0FX8nxh Fml0r2In671kf74sCHrHm97tmGqfEXzhcZLO8Jp4ma9Ot0JJOYfmdYyxJHkatJAtkOS2 ISXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721075438; x=1721680238; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SfAFcOpsEWKKzNdGbGiFbAnxGKMzUl+aLp4W8AHT3yY=; b=RKB1IeeYMODE03FT2rvpEiGkMXyLkypHTIIOYo4i+SF46nMsLrejfmykcl26prkjON ke1XnY1d9EBs8m9Z7HHq2YtA1BT15oGuVxO2+1CHv8Lkqi/9qR+XvERunX06W47MT6na +g68uVmslIc62LRUfdbwMCIJFRZiy7IQW/b+/y78+Ta58tYkeQ0+2Xo5hCSqnKE+ZPfU UC+tHoVa2NFKNP5qZcuRteQXn2X3MxpjtZyl5y2qwd9RcdmHLt1R5Bj0OXV28mMN10B/ lv5JIU60ANBr9+WjwOcQoo8NVHn9B9YYaAw98bSPUSBO3fHxR9ZSZNe0HGJksrTzy0GR RbQQ== X-Gm-Message-State: AOJu0YyHuCbh2Qi4vGkTruZUjzthbCgYnD8MB3Uiw6uKeAqduDuFV9kv mY8MYHIDHpFzy0YWUIS/33CjmD8J0ar3Wgi9ka5WOeTZfW/fpyitdFhhnxr+G6MqAoK0/EPDLkP DmCZbEL01Hzt/OGKFcLxdERERPIGFtvLh X-Google-Smtp-Source: AGHT+IEg4Zju6M62BFVxqHhZnjYRzvFFgKNinoIT2DdahagGqirlumCFaV5/pUSCHd/2HGSm9P3p931WRrXlu6+xQ5c= X-Received: by 2002:a05:6122:3193:b0:4ef:3a26:6eb5 with SMTP id 71dfb90a1353d-4f4d0528357mr179463e0c.0.1721075438425; Mon, 15 Jul 2024 13:30:38 -0700 (PDT) MIME-Version: 1.0 References: <20240713220545.cgjghaggksov3xkt@hjp.at> <20240715142744.7e7a3wtdfxinochf@hjp.at> In-Reply-To: <20240715142744.7e7a3wtdfxinochf@hjp.at> From: sud Date: Tue, 16 Jul 2024 02:00:27 +0530 Message-ID: Subject: Re: Dropping column from big table To: pgsql-general@lists.postgresql.org, Laurenz Albe , "Peter J. Holzer" Content-Type: multipart/alternative; boundary="000000000000239cd3061d4f1a81" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000239cd3061d4f1a81 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jul 15, 2024 at 7:58=E2=80=AFPM Peter J. Holzer = wrote: > > > Hm, true. > > > > You can always do > > > > UPDATE tab SET id =3D 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. > > > Thank You very much. As I understand, after dropping a column, it will still internally hold the "NOT NULL" values in that column for all the rows, even though it's not visible outside. So, after the DROP column, it will force update any of the columns as below, Then it will force create another copy of each of the rows even if the column is updated to the same value. The new copy will have the dropped column with values as NULL. And the post "VACUUM FULL '' will clean all the rows with "NOT NULL '' values of that dropped column and thus reclaim the space. But the only issue would be "VACUUM FULL" will take a table lock and also it may take longer to run this vacuum on the full table considering the size of the table in TB's. Thus, is it fine to just leave it post execution of the "update" statement , so that the normal vacuum operation (which will be online operation) and that will take care of the removal of old rows ? UPDATE tab SET id =3D id; VACUUM (FULL) tab; And also, As you mentioned we may also leave it as is and wait for the partition to be dropped, so that the dropped column with "not null" values which are still lying under the hood and are occupying space will be removed automatically. But even then, is that dropped column still lying in the rows with null values in it throughout its lifecycle, till the table exists in the database? Seems there is no other option exist to drop the column with space reclaimed from the table in immediate effect, other than above discussed. --000000000000239cd3061d4f1a81 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Mon, Jul 15, 2024 at 7:58=E2=80=AFPM P= eter J. Holzer <hjp-pgsql@hjp.at= > wrote:

> Hm, true.
>
> You can always do
>
>=C2=A0 =C2=A0UPDATE tab SET id =3D id;
>
> followed by
>
>=C2=A0 =C2=A0VACUUM (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.

=C2=A0 =C2=A0=C2=A0
Thank=C2=A0You very much.

As I understand, after dropping a column, it will still int= ernally hold the "NOT NULL" values in that column for all the row= s, even though it's not visible outside.

So, after the DROP colu= mn, =C2=A0it will force update any of the columns as below, Then it will fo= rce create another copy of each of the rows even if the column is updated t= o the same value. The new copy will have the dropped column with values as = NULL. And the post "VACUUM FULL '' will clean all the rows wit= h "NOT NULL '' values of that dropped column and thus reclaim = the space.

But the only issue would be "VACUUM FULL" will= take a table lock and also it may take longer to run this vacuum on the fu= ll table considering the size of the table in TB's. Thus, is it fine to= just leave it post execution of the "update" statement , so that= the normal vacuum operation (which will be online operation) and that will= take care of the removal of old rows ?

=C2=A0UPDATE tab SET id =3D = id;
=C2=A0VACUUM (FULL) tab;
=C2=A0
=C2=A0And also, As you mention= ed we may also leave it as is and wait for the partition to be dropped, so = that the dropped column with "not null" values which are still ly= ing under the hood and are occupying space will be removed automatically. B= ut even then, is that dropped column still lying in the rows with null valu= es in it throughout its lifecycle, till the table exists in the database? <= br>=C2=A0
=C2=A0Seems=C2=A0there is no other option exist to drop the co= lumn with space reclaimed from the table in immediate effect, other than ab= ove discussed.
=C2=A0
--000000000000239cd3061d4f1a81--