Re: calculating table and index size

From: Günce Kaya <guncekaya14(at)gmail(dot)com>
To: Steven Chang <stevenchang1213(at)gmail(dot)com>
Cc: Guillaume Lelarge <guillaume(at)lelarge(dot)info>, "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>, PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: calculating table and index size
Date: 2017-04-07 07:11:54
Message-ID: CAAV2-mXSUPVpdE3as_93GJPsp5Ke=AYX_ObrT0qwm7ChZeEXSA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

Hi again,

Sorry for delay.

Guillaume, I read your answer for first question but It's not clear to me.
The table has a column and index also use that column. so in that example,
I think table size and index size should be equal. Why these are not equal?

Your answer for second question is pretty clear. Thanks for your both of
answers.

Steven, thanks for your response. I got a new information thanks to you.

Regards,

Gunce Kaya

On Wed, Apr 5, 2017 at 1:02 PM, Steven Chang <stevenchang1213(at)gmail(dot)com>
wrote:

> Hello,
>
> try pgstattuple() and pgstatindex() , I think you will figure it out.
>
> Steven
>
> 2017-04-05 16:56 GMT+08:00 Guillaume Lelarge <guillaume(at)lelarge(dot)info>:
>
>> Hi,
>>
>> 2017-04-05 9:44 GMT+02:00 Günce Kaya <guncekaya14(at)gmail(dot)com>:
>>
>>> Hi all,
>>>
>>> I have some questions about calculating table and index size.
>>>
>>> I have a dummy table which has an integer column and its index. The
>>> table has 1400000 rows and all of rows are same thats value is 20000000.
>>> Table size is 50MB and index size is 31MB. Why there is too much size
>>> difference between table and its index? what happen on data files when we
>>> add index?
>>>
>>>
>> You have metadata informations in the table datafiles that you don't have
>> on the index datafiles. For example, all the system columns for each line.
>>
>>
>>> Second question is that after created table, table size was 0 byte. I
>>> inserted a row as 120 then table size was 8192 byte. I inserted five times
>>> same value to the table and table size is still 8192 bytes. Table size
>>> changed after inserted lots of rows. Table size was stabile till first few
>>> hundred rows. why table size didn't change when I inserted lots of rows?
>>>
>>>
>> PostgreSQL works with 8KB blocks. When you insert a line, it puts it on a
>> block, but this block may contain many lines. So your next new lines still
>> fit in the first block... until it doesn't, and you'll see a new block
>> coming, making your table datafile grows to 16KB. And so on and so on.
>>
>>
>> --
>> Guillaume.
>> http://blog.guillaume.lelarge.info
>> http://www.dalibo.com
>>
>
>

--
Gunce Kaya

Linkedin <https://tr.linkedin.com/in/guncekaya> - Twitter
<https://twitter.com/gguncesi> - Blog
<http://www.guncekaya.blogspot.com.tr/>

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Robin LUCBERNET 2017-04-07 12:12:39 Re: How do you manage cluster replication and failover ?
Previous Message Poul Kristensen 2017-04-06 16:16:42 Re: How do you manage cluster replication and failover ?

Browse pgsql-general by date

  From Date Subject
Next Message Christoph Berg 2017-04-07 13:38:23 Re: A change in the Debian install
Previous Message Chris Mair 2017-04-07 06:26:59 Re: keeping WAL after dropping replication slots