Re: Postgres table size

From: SHARMILA JOTHIRAJAH <sharmi_jo(at)yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Erik Jones <erik(at)myemma(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Postgres table size
Date: 2007-11-21 17:51:22
Message-ID: 158238.43855.qm@web31110.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>>> Calculation
>> >varchar = (overhead) 4 + (actual length of string) 3 = 7 bytes
>> >*for 5 varchar cols =
>> >5*7 = 35 bytes
>> >
>> >numeric (according to manual--- The actual storage requirement is

>> >two bytes for each group of four decimal digits, plus eight bytes
>>> overhead )
>>> numeric = ( 10/4)*2 +8 = 13 bytes
>>> *for 5 numeric cols = 13 *5 = 65

> >Not that it will make much difference, but you need to round up in
> >the 10/4 part so you get 14 bytes, not 13.

>Also, this calculation is ignoring the fact that (pre-8.3) varlena
>values have to be int-aligned, so there's wasted pad space too.
>The varchar values really need 8 bytes each, and the numeric values
>16, so the actual data payload in each row is 120 bytes. Then add
>HeapTupleHeader (28 bytes), and then MAXALIGN the whole row size.
>So the rowsize would be either 148 or 152 bytes depending on if you
>were on a machine with 8-byte MAXALIGN. Then add the per-row item
>pointer, giving total per-row space of 152 or 156 bytes. That
>means you can fit either 53 or 52 rows per page, giving either 188
>or 192 pages as the minimum possible file size. Evidently, Sharmila
>is using a MAXALIGN=4 machine and has a few dead rows in there.

Thanks for the detailed explanation Tom. You are rigt...The number of pages for this tables as per pg_class is 189.

I have a few questions
1. How do you find the MAXALIGN of the machine? And what is that used for?
2. How does null columns account for this space. For example, if I have the same table (10 cols --5 varchars and 5 numerics) in which 8 cols are null and 2 cols(1 varchar and 1 num) are not null, how is the storage space affected for this case?

Thanks again
sharmila

____________________________________________________________________________________
Get easy, one-click access to your favorites.
Make Yahoo! your homepage.
http://www.yahoo.com/r/hs

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2007-11-21 17:53:33 Re: Restart a sequence regularly
Previous Message Richard Huxton 2007-11-21 17:51:03 Re: loading a funtion script from a file