Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 8A388B5DC1A for ; Wed, 14 Sep 2011 18:06:04 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 43603-07 for ; Wed, 14 Sep 2011 21:05:57 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 252BCB5DC10 for ; Wed, 14 Sep 2011 18:05:56 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p8EL5tq7006115; Wed, 14 Sep 2011 17:05:55 -0400 (EDT) To: Rob Audenaerde cc: Guillaume Lelarge , "pgsql-admin@postgresql.org" Subject: Re: database size much bigger than tablespaces on filesystem In-reply-to: <1D020918205F334CBDD5CE7DF2038A2E15A581245C@IE2RD2XVS271.red002.local> References: <1D020918205F334CBDD5CE7DF2038A2E15A5812457@IE2RD2XVS271.red002.local>, <1316001615.2110.13.camel@localhost.localdomain> <1D020918205F334CBDD5CE7DF2038A2E15A581245A@IE2RD2XVS271.red002.local>, <904.1316015234@sss.pgh.pa.us> <1D020918205F334CBDD5CE7DF2038A2E15A581245C@IE2RD2XVS271.red002.local> Comments: In-reply-to Rob Audenaerde message dated "Wed, 14 Sep 2011 09:04:29 -0700" Date: Wed, 14 Sep 2011 17:05:55 -0400 Message-ID: <6114.1316034355@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/103 X-Sequence-Number: 38340 Rob Audenaerde 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