Skip navigation

Well, so my requirement this time was to get the size of all tables in a particular schema. HOW?

AFAIK, there was no direct way to fulfill my requirement. So wrote my own query..

SELECT pg_size_pretty(sum(pg_total_relation_size(‘archival.’||table_name))::bigint)
FROM information_schema.tables
WHERE table_schema=’archival’;

Where ‘archival’ is the schema name. Checkout the type-casting.
Short explanation: sum() returns int type, but pg_size_pretty() takes bigint as the param data type. Hence the type casting.

NB:- when copying the query, take care of the quotes.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


+ two = 4

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>