Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pg_relation_size command is not providing size [duplicate]

I need to find size of a table in posgreSQL. I am using following command but it is giving me 0 as an output. Could you please inform me how can I get the size of a table?

INPUT:

select pg_relation_size('tableName');

OUTPUT:

pg_relation_size 

  0

(1 row)
like image 899
Beautiful Mind Avatar asked Oct 27 '25 13:10

Beautiful Mind


1 Answers

I know this is ancient but I just ran into the same issue. It was due to the fact that the table is a partitioned one, so technically it doesn't have a real size. To get the combined size of all the partitions, check out this question.

Or you could simply make use of the inheritance catalog like:

SELECT count(*) AS child_amount, pg_size_pretty(sum(pg_relation_size(inhrelid::regclass))) AS child_size
FROM pg_inherits 
WHERE inhparent='tableName'::regclass;
like image 65
Woodly0 Avatar answered Oct 29 '25 07:10

Woodly0