Mnesia table creation on disc not ram?

For full disclosure, I’m new to Erlang. I am trying to create a mnesia table on disc not ram. This code does so successfully.:

initialize_mnesia() -> 
    mnesia:stop(),
    application:set_env(mnesia, dir, "/tmp/star_watch_db"),
    mnesia:create_schema([node()]),
    mnesia:start(),
    CreateResult = mnesia:create_table(
        apodimagetable,
        [
            {attributes, record_info(fields, apodimagetable)},
            {index, [#apodimagetable.date, #apodimagetable.title, #apodimagetable.hdurl]}, 
            {type, ordered_set},
            {disc_copies, nodes()}
        ]),
    mnesia:change_table_copy_type(apodimagetable, node(), disc_copies).

If I omit the call to change_table_copy(), the ‘apodimagetable’ is NOT disc based. It is ram based. All the docs I’ve read do not mention the need for calling change_table_copy_type. What am I missing?

1 Like

In mnesia:create_table you use nodes():

which without parameters does not return “itself”:

$ erl                                                                                                                                                      main
Erlang/OTP 25 [erts-13.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit:ns]

Eshell V13.0  (abort with ^G)
1> nodes().
[]

If you change it to [node()] in the create_table-call it should work without the change_table_copy_type, where you use node()

3 Likes

Your code is wrong, you have created mnesia schema on self node but you have created a disc table on the peer nodes that are connected to this node

Thank you!

1 Like