4

In a multi-tenant only one DB, one column is used to isolate customers data, that is customer_id.

Is it possible to get the storage size of a certain customer in all tables?

0

1 Answer 1

10

You can use pg_column_size() to get the size of a complete row, not only for a single column.

So to find the size of all rows for a specific customer, you can use something like this:

select sum(pg_column_size(t) + 24) 
from the_table t
where customer_id = 42;

(The 24 is the storage overhead per row in a table)

You would need to do that for all tables you are interested in.

This does however not include the size of those rows in the indexes.

4
  • Do you mean that the size of indexes is not retrieved?
    – simo
    Commented Mar 14, 2017 at 10:51
  • @simo: correct, that query does not include the size of indexed columns.
    – user1822
    Commented Mar 14, 2017 at 10:55
  • is there any workaround to get indexed columns too?
    – simo
    Commented Mar 14, 2017 at 11:01
  • hands down the best way to do this Erwin's way here Commented Mar 14, 2017 at 14:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.