0

This question already has an answer here:

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?

marked as duplicate by Evan Carroll, Marco, RLF, Colin 't Hart, LowlyDBA Mar 16 '17 at 18:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

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.

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

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