Thread: Disk space occupied by a table in postgresql

Disk space occupied by a table in postgresql

From
aravind chandu
Date:
Hello,

                    I installed postgresql on linux system, I create a table and inserted a large data into the table what I would like to know is how to calculate the disk space occupied by the table .Is there any procedure to find it out or simply a command .Please give me some suggestion.


Thank You,
Avin.

Re: Disk space occupied by a table in postgresql

From
"Fouad Zaryouh"
Date:
Hi Aravind,

Run the following query

SELECT relname, reltuples, relpages * 8 / 1024 AS "MB" FROM pg_class ORDER BY relpages DESC;


relname = table name
relpages = size in MB
reltuples = number of rows.

Hope this help.



Fouad Zaryouh

http://www.flipcore.com




On Sat, Aug 9, 2008 at 3:18 AM, aravind chandu <avin_friends@yahoo.com> wrote:
Hello,

                    I installed postgresql on linux system, I create a table and inserted a large data into the table what I would like to know is how to calculate the disk space occupied by the table .Is there any procedure to find it out or simply a command .Please give me some suggestion.


Thank You,
Avin.


Re: Disk space occupied by a table in postgresql

From
hubert depesz lubaczewski
Date:
On Sat, Aug 09, 2008 at 12:18:46AM -0700, aravind chandu wrote:
>                     I installed postgresql on linux system, I create a
>                     table and inserted a large data into the table
>                     what I would like to know is how to calculate the
>                     disk space occupied by the table .Is there any
>                     procedure to find it out or simply a command
>                     .Please give me some suggestion.

select pg_relation_size('table_name');
or
select pg_total_relation_size('table_name');

both return size in bytes.

pg_total_relation_size includes disk space used by indexes and external
storage (long texts are kept not in table datafile, but in separate
"toast" tables).

Best regards,

depesz

--
Linked in: http://www.linkedin.com/in/depesz
jid/gtalk: depesz@depesz.com
aim:       depeszhdl
skype:     depesz_hdl

Re: Disk space occupied by a table in postgresql

From
Andreas Kretschmer
Date:
aravind chandu <avin_friends@yahoo.com> schrieb:

> Hello,
>
>                     I installed postgresql on linux system, I create a table
> and inserted a large data into the table what I would like to know is how to
> calculate the disk space occupied by the table .Is there any procedure to find
> it out or simply a command .Please give me some suggestion.

You can use the pg_relation_size() - function, described here:
http://www.postgresql.org/docs/8.3/interactive/functions-admin.html


Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

Re: Disk space occupied by a table in postgresql

From
Reid Thompson
Date:
On Sat, 2008-08-09 at 04:59 -0400, Fouad Zaryouh wrote:
> Hi Aravind,
>
> Run the following query
>
> SELECT relname, reltuples, relpages * 8 / 1024 AS "MB" FROM pg_class
> ORDER BY relpages DESC;
>
>
>
> relname = table name
> relpages = size in MB
> reltuples = number of rows.
>
> Hope this help.
>
>
>
> Fouad Zaryouh
>
> http://www.flipcore.com
>
>
>
>
> On Sat, Aug 9, 2008 at 3:18 AM, aravind chandu
> <avin_friends@yahoo.com> wrote:
>         Hello,
>
>                             I installed postgresql on linux system, I
>         create a table and inserted a large data into the table what I
>         would like to know is how to calculate the disk space occupied
>         by the table .Is there any procedure to find it out or simply
>         a command .Please give me some suggestion.
>
>
>         Thank You,
>         Avin.
>
>
>
>

This may be of use in recent versions...
select pg_size_pretty(pg_database_size('table_name'))