1
votes

I want to find the total size of a mnesia database. I have only one node.

Can I get the size of mnesia from some function or can I calculate it somehow?

I have looked in the documentation http://erlang.org/doc/man/mnesia.html, but I cannot find a fucntion to get such information for the whole database.

Do I need to calculate it per table using table_info/2? And if so how?

NOTE: I don't know how to do that with the current data points, the size is 2 (for testing I have only 2 entries) and memory is 348.

1
Was the DB created with disc_copies option? Or RAM only?Aleksei Matiushkin
@AlekseiMatiushkin I didn't specify anything since I was testing it out. From what I found disc_copies is not set by default.ipinak
memory option returns the number of words used, based on your CPU architecture it's 32/64bit so word size is 4/8 bytes. In your case 348 * 4 or * 8Roman Rabinovich

1 Answers

1
votes

You need to iterate over all the tables with mnesia:system_info(tables) and read each table memory with mnesia:table_info(Table, memory) to obtain the number of words occupied by your table. To transform that value to bytes, you can first use erlang:system_info(wordsize) to get the word size in bytes for your machine architecture(on a 32-bit system a word is 4 bytes and 64 bits it's 8 bytes) and multiply it by your Mnesia table memory. A rough implementation:

%% Obtain the memory in of bytes of all the mnesia tables.
-spec get_mnesia_memory() -> MemInBytes :: number().
get_mnesia_memory() ->
  WordSize = erlang:system_info(wordsize),
  CollectMem = fun(Tbl, Acc) ->
   Mem = mnesia:table_info(Tbl, memory) * WordSize,
   Acc + Memory
  end,
  lists:foldl(CollectMem, 0, mnesia:system_info(tables)).