Re: How to evaluate disk space needed by a table - Mailing list pgsql-general

From Stephen Frost
Subject Re: How to evaluate disk space needed by a table
Date
Msg-id 20130528044204.GY8597@tamriel.snowman.net
Whole thread Raw
In response to How to evaluate disk space needed by a table  (高健 <luckyjackgao@gmail.com>)
List pgsql-general
* 高健 (luckyjackgao@gmail.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

Attachment

pgsql-general by date:

Previous
From: 高健
Date:
Subject: How to evaluate disk space needed by a table
Next
From: Nikhil G Daddikar
Date:
Subject: How to check if Postgresql files are OK