Re: How to evaluate disk space needed by a table

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: 高健 <luckyjackgao(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to evaluate disk space needed by a table
Date: 2013-05-28 04:42:04
Message-ID: 20130528044204.GY8597@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

* 高健 (luckyjackgao(at)gmail(dot)com) wrote:
> So , Is there any method to correctly evaluate disk space one table will
> need,
> given the table's column data types and , estimated record numbers ?

The simplest might be to do exactly what you did- create the table and
then check the size with a subset of records. It won't be exactly
linear from there but it'd provide a good estimate.

Otherwise, you need to consider the various additional fields which
PostgreSQL adds to every tuple to keep track of visibility and other
information. Then you have to add in the page header and the other bits
of the tuple header beyond the system columns. Lastly, you need to
figure out how many tuples will actually fit on a page based on their
size, because there will be gaps if the tuple doesn't fit exactly into
the remaining space in the page.

btw, there are helper functions to get disk usage-
pg_total_relation_size() and pg_relation_size() come to mind, though
there are also others.

Thanks,

Stephen

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Nikhil G Daddikar 2013-05-28 04:47:50 How to check if Postgresql files are OK
Previous Message 高健 2013-05-28 04:18:58 How to evaluate disk space needed by a table