pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Morus Walter <morus.walter@tanto.de>
To: Daniel Rubio <drubior@tinet.org>
Subject: Re: schema sizes
Date: Thu, 3 Mar 2005 08:34:28 +0100
Message-ID: <16934.48644.771352.662613@tanto-xipolis.de> (raw)
In-Reply-To: <4225B600.1000303@tinet.org>
References: <4225B600.1000303@tinet.org>

Daniel Rubio writes:
> Hi all!
> 
> We want to obtain the size of the diferent schemas of some databases.
> We've installed dbsize and it works fine, but it returns the size of all 
> the database.
> Exists some method to determine the size of a concrete schema?
> 
I use 
SELECT nspname, 
sum(relpages * cast( 8192 AS bigint )) as "table size", 
sum( ( select sum(relpages) 
      from pg_class i, pg_index idx 
      where i.oid = idx.indexrelid 
      and t.oid=idx.indrelid ) ) * cast( 8192 AS bigint ) as "index size", 
sum ( relpages * cast( 8192 AS bigint ) + ( select sum(relpages) 
      from pg_class i, pg_index idx 
      where i.oid = idx.indexrelid 
      and t.oid=idx.indrelid ) * cast( 8192 AS bigint ) ) as "size"  
FROM pg_class t, pg_namespace 
WHERE relnamespace = pg_namespace.oid 
and pg_namespace.nspname not like 'pg_%' 
and pg_namespace.nspname != 'information_schema' 
and relkind = 'r' group by nspname;

to sum over all tables/indices of a schema.
Note that the input for the sum is relpages in pg_class and this value
is only updated by VACUUM, ANALYZE und CREATE INDEX.
So you should analyze all tables before you execute the statement.



view thread (3+ messages)  latest in thread

Message-ID: <16934.48644.771352.662613@tanto-xipolis.de>
Permalink:  ../16934.48644.771352.662613@tanto-xipolis.de/
Also on:    postgresql.org/message-id/16934.48644.771352.662613@tanto-xipolis.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: morus.walter@tanto.de, drubior@tinet.org
  Subject: Re: schema sizes
  In-Reply-To: <16934.48644.771352.662613@tanto-xipolis.de>
  References: <4225B600.1000303@tinet.org> <16934.48644.771352.662613@tanto-xipolis.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox