Re: How much size saved by updating column to NULL ?

From: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How much size saved by updating column to NULL ?
Date: 2024-01-12 15:48:29
Message-ID: CANzqJaAWS0kO7HACiv_rXa2y=svTWDy-aRErVvzr1QLzs=znjA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jan 12, 2024 at 7:45 AM Sébastien TANIERE <seb(dot)taniere(at)gmail(dot)com>
wrote:

> Hello,
> in my company, some columns rarely used in a PG database 14.8 have been
> set to NULL in order to save disk space (datecreation & acteurcreation in
> following table) .
>
> create table example
> (
> id varchar(25) not null,
> datecreation timestamp(6),
> acteurcreation varchar(50),
> valeurunit smallint
> )
>
> I am wondering if it is really useful for every type of column.
> Intuitively, i would say that it does not save space for fixed field
> datecreation as it is a fixed size column.
>
> Do we save 8 bytes by timestamp column updated to NULL or not ?
>

I don't think the record on the page is rewritten in a more compact form.
Even if it were, the page would just have a small hole in it.

A different version of this question might be whether the tuple is deleted
and then the hopefully smaller row inserted some where else when
"UPDATE example SET datecreation = NULL;" is executed. But of course then
you'd use *more* disk space, since now the file(s) will be full of holes.
Vacuum will clean them up so that new data can be inserted there, but the
files would not be shrunk.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2024-01-12 16:20:22 Re: How much size saved by updating column to NULL ?
Previous Message Kiran K V 2024-01-12 15:23:06 Issue with loading unicode characters with copy command