[erlang-questions] Re-using Mnesia disk files for a different node

Philip Clarke <>
Mon Sep 23 12:12:59 CEST 2013


Hi Yash,

(forwarding my reply to the list this time to see if there is any feedback
on this advice)

Unfortunately the mnesia schema lists which nodes are associated with which
tables.  In your case your new node (node2) will look at the schema and
know that it does not have any tables.  It would be able to have remote
access to the tables if node1 was still running, but this does not suit
your use case.

If you want to move a mnesia database from one node to another, I have
found that you need to follow there are three steps:
1) backup the current database with mnesia:backup
2) rewrite the schema table in your backup (to replace node1 with node2)
using mnesia:traverse_backup
3) restore the backup to your new node with mnesia:restore

For step 2, see the function change_node_name in the code example in
http://www.erlang.org/doc/apps/mnesia/Mnesia_chap7.html#id78880

Regards
Philip


On Mon, Sep 23, 2013 at 7:58 AM, Yash Ganthe
<>wrote:

>  Hi,****
>
> ** **
>
> On a node named  I created an Mnesia schema using:****
>
> mnesia:create_schema([node()]).****
>
> and created a table using:****
>
> mnesia:create_table(tab1, [{disc_copies, [node()]}, {attributes,
> record_info(fields, tab1)}]).****
>
> ** **
>
> The mnesia directory was set to "mnesia_node1". The directory was created
> and the DB files were created inside it.****
>
> ** **
>
> Once the node was stopped, the DB files still exist in the directory. I
> hoped to re-use the DB as the mnesia DB for another node, node2.****
>
> ** **
>
> So I started the other node using:****
>
> erl -name node2 -mnesia dir "mnesia_node1".****
>
> ** **
>
> On node2 when I start mnesia and do a tv:start(), I see the tab1 listed in
> the schema. However, it shows no records. I was expecting Mnesia to use the
> directory as the location of all DB files.****
>
> ** **
>
> Is there something I have missed?****
>
> ** **
>
> Thanks,****
>
> Yash****
>
> DISCLAIMER ========== This e-mail may contain privileged and confidential
> information which is the property of Persistent Systems Ltd. It is intended
> only for the use of the individual or entity to which it is addressed. If
> you are not the intended recipient, you are not authorized to read, retain,
> copy, print, distribute or use this message. If you have received this
> communication in error, please notify the sender and delete all copies of
> this message. Persistent Systems Ltd. does not accept any liability for
> virus infected mails.
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130923/0ab71334/attachment.html>


More information about the erlang-questions mailing list