pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jerry Sievers <gsievers19@comcast.net>
To: Luis <luisico@gmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Difference in the size of database size and relations
Date: Tue, 10 Dec 2013 12:07:59 -0600
Message-ID: <86vbyw1sw0.fsf@jerry.enova.com> (raw)
In-Reply-To: <CAM-gcbSfTp6co+vo5s6UMy4b9oGf9yLFZX9WJKrBR1=P8BoXzw@mail.gmail.com>
References: <CAM-gcbSfTp6co+vo5s6UMy4b9oGf9yLFZX9WJKrBR1=P8BoXzw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-admin>

Luis <luisico@gmail.com> writes:

> Hi,
>
> I have noticed a weird thing in different databases.
> When I run pg_database_size on some databases they report a pretty
> high value and if I take a look to all relations the sum of all of
> them is not even the half of the one reported by pg_database_size.
>
> Although I've seen this in different databases, this is a specific example.
>
>
> This are the sizes reported by this query:
>
> SELECT pg_size_pretty(pg_relation_size(C.oid)) AS "size"
>   FROM pg_class C
>   LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
>   WHERE nspname NOT IN ('pg_catalog', 'information_schema')
>   ORDER BY pg_relation_size(C.oid) DESC
>   LIMIT 20;
>

Try just comparing what pg_database_size() tells you vs a sum() over
relpages*8192 (assuming standard page size).  You may have to do some
casting to bigint depending how large your DB is.

>   size
> ---------
>  99 MB
>  45 MB
>  10 MB
>  8528 kB
>  5280 kB
>  4352 kB
>  3184 kB
>  1304 kB
>  1152 kB
>  896 kB
>  544 kB
>  528 kB
>  336 kB
>  336 kB
>  336 kB
>  304 kB
>  296 kB
>  288 kB
>  272 kB
>  248 kB
>
> And this is the database size reported by this query:
> SELECT pg_size_pretty(pg_database_size('mydb'));
>
>  pg_size_pretty
> ----------------
>  3539 MB
>
> I've read about LOBs but I don't seem to have any.
>
> Any idea where the space is being used?
>
> Thanks

-- 
Jerry Sievers
Postgres DBA/Development Consulting
e: postgres.consulting@comcast.net
p: 312.241.7800


-- 
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin



view thread (8+ messages)

Message-ID: <86vbyw1sw0.fsf@jerry.enova.com>
Permalink:  ../86vbyw1sw0.fsf@jerry.enova.com/
Also on:    postgresql.org/message-id/86vbyw1sw0.fsf@jerry.enova.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: gsievers19@comcast.net, luisico@gmail.com
  Subject: Re: Difference in the size of database size and relations
  In-Reply-To: <86vbyw1sw0.fsf@jerry.enova.com>

* 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