Re: Finding the size of your biggest relations

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Artem Tomyuk <admin(at)leboutique(dot)com>
Cc: depesz(at)depesz(dot)com, pgsql-admin(at)postgresql(dot)org
Subject: Re: Finding the size of your biggest relations
Date: 2016-09-23 14:30:52
Message-ID: 13514.1474641052@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Artem Tomyuk <admin(at)leboutique(dot)com> writes:
> Sorry,
> this query

> SELECT nspname || '.' || relname AS "relation",
> pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
> FROM pg_class C
> LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
> WHERE nspname NOT IN ('pg_catalog', 'information_schema')
> AND C.relkind <> 'i'
> AND nspname !~ '^pg_toast'
> ORDER BY pg_total_relation_size(C.oid) DESC
> LIMIT 20;

I think what's happening is that your ORDER BY is sorting nulls first.
So what's coming out at the top is temp relations that were dropped
between the time of the statement snapshot and the time that
pg_total_relation_size looked at them. Try ORDER BY ... DESC NULLS LAST.

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Gilberto Castillo 2016-09-23 15:14:47 Re: Recommended cluster locale (initdb)?
Previous Message Bruce Momjian 2016-09-23 14:30:40 Re: does cluster created through initdb update postgres-reg.ini with its entry?