2

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)
ntalbs
  • 28,700
  • 8
  • 66
  • 83
Beautiful Mind
  • 5,828
  • 4
  • 23
  • 42

2 Answers2

2

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;
Woodly0
  • 187
  • 2
  • 13
1

This is probably because tableName is a view.

Example:

CREATE VIEW dummy AS SELECT 1;
SELECT pg_relation_size('dummy');

Result:

 pg_relation_size 
------------------
                0
(1 row)

Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156