问题
I have a complete mnesia ram_copies-only database but I am experiencing problems adding a disk_copy table to a node. At the moment I do:
Create all my ram_copy tables/nodes
Start mnesia on the disk_copy-to-be node.
- Create a new schema (I didnt create a schema for the ram_copy tables) using
mnesia:create_schema([Node])
- Copy the table I wish to be a disk_copy, using
mnesia:add_table_copy(table, Node, disk_copy)
- I then wait for the tables to be created
Everything seems to go according to plan (no run-time errors), but when I go to the pwd(). directory and check, there is no file reflecting the table I just created. Also when I call mnesia:info()
on the node, there are no disk_copy tables, only a ram_copy schema.
回答1:
Can you check that the field "running db nodes" lists both nodes that you have started ? It could be that you did not add the second node to the mnesia cluster.
So if your second node was called BNode, then on the first node you would run these commands in this order:
1) mnesia:change_config(extra_db_nodes, [BNode]).
2) mnesia:add_table_copy(table, BNode, disc_copies).
Second: I think you should be creating the schema (step 3) before you start up mnesia on the disk_copy-to-be node (step 2).
This is what I did to create the schema you require:
Lets assume you have 2 nodes NodeA and NodeB.
Make sure that there is no Mnesia dir already existing before you start this.
%% From NodeA, setup the A node
erl -sname a -setcookie cookie
mnesia:start().
mnesia:create_table(mytable, [{attributes, [field1, field2]}]).
%% From NodeB, setup the B node
erl -sname b -setcookie cookie
net_adm:ping(NodeA).
mnesia:create_schema([node()]).
mnesia:start().
%% From NodeA, Add the NodeB to the mnesia cluster
[BNode | _] = nodes().
mnesia:change_config(extra_db_nodes, [BNode]).
%% From NodeA, add NodeB as a disc copy
mnesia:add_table_copy(mytable, BNode, disc_copies).
来源:https://stackoverflow.com/questions/13398632/creating-mnesia-disk-copies-of-existing-ram-table