Re: database size much bigger than tablespaces on filesystem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rob Audenaerde <Rob(dot)Audenaerde(at)Valuecare(dot)nl>
Cc: Guillaume Lelarge <guillaume(at)lelarge(dot)info>, "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: database size much bigger than tablespaces on filesystem
Date: 2011-09-14 21:05:55
Message-ID: 6114.1316034355@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Rob Audenaerde <Rob(dot)Audenaerde(at)Valuecare(dot)nl> writes:
> It gets stranger. I try this:

> select
> tablename
> , pg_relation_size(tablename)
> , pg_size_pretty(pg_relation_size(tablename) ) as relsize
> , pg_size_pretty(pg_total_relation_size(tablename) ) as disksize
> , pg_total_relation_size(tablename)
> from pg_tables where schemaname <> 'information_schema'
> order by 2 desc

> And all the tables report a 'disksize' larger than the 'relsize',
> which seems natural. The biggest table (relsize) is around 5 GB.

pg_relation_size isn't going to count indexes nor toast tables, and
toast in particular could be where a lot of the space is. I'd suggest
sorting by pg_total_relation_size to see if anything jumps out at you.

Another problem with the above query is that it supposes that there are
no similarly-named tables in different schemas. If there are, you'll
get multiple reports of the size of the one that is visible in your
search path, and no reports for the others. If I were doing this,
I'd not rely on pg_tables but look at pg_class directly so I could use
the OID, something like

select relname, pg_total_relation_size(c.oid)
from pg_class c where relkind = 'r'
order by 2 desc

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message marvin.deoliveira 2011-09-15 22:32:53 RESTORE IS TO SLOW
Previous Message Steve Crawford 2011-09-14 18:06:52 Re: pg_upgrade difficulties