Sizing Up Your Partitions

Just a handy little function I wrote today to help determine the total size of your [ partitioned tables] (inclusive of all your partitions). I had a plpgsql version but this one seems simpler. It doesnt include indexes but could be modified to do so. Hopefully it will be of use to others.
CREATE OR REPLACE FUNCTION public.pg_parts_size(text) RETURNS bigint AS $$ SELECT sum(pg_relation_size(oid))::bigint FROM pg_class WHERE oid IN (SELECT inhrelid FROM pg_inherits WHERE inhparent = (SELECT c.oid FROM pg_class c join pg_namespace n ON (n.oid=c.relnamespace) WHERE nspname = substr($1,1,strpos($1,'.')-1) AND relname = substr($1,strpos($1,'.')+1,length($1)) ) ) $$ LANGUAGE sql; pgods=# select pg_size_pretty(pg_relation_size('ods.ods_tblhits')); pg_size_pretty ---------------- 0 bytes (1 row) pgods=# select pg_size_pretty(pg_parts_size('ods.ods_tblhits')); pg_size_pretty ---------------- 165 GB (1 row)