[erlang-questions] Creating backup of ram based Mnesia on Disc

Håkan Mattsson <>
Mon May 21 12:20:36 CEST 2012


On Mon, May 21, 2012 at 9:31 AM, Arun Muralidharan <> wrote:
> Hi,
>
> Currently I am creating the table in following steps:
>
> mnesia:start(),
> mnesia:create_schema([node()]),
>
> mnesia:create_table(guiding_data,
>                          [
>                            {attributes, record_info(fields, guiding_data)},
>                            {ram_copies,[node()]}
>                          ]),
>
> Now, all the data I load (huge amounts) will reside in RAM as expected.
> But what I would like here is to have a backup of all the data residing
> in RAM to be also present on disk, so that in case i stop and start Mnesia
> again,
> it should load the data from the disk to memory, instead of loading the data
> again into memory explicitly by me.
>
> What I can do here is :
> 1) mnesia:change_table_copy_type(schema,node(),disc_copies),
>    Now, this would create a disc copy, but all my queries to mnesia would
>    access disk. right ? This is what i observed and didnt want.

No, for disc_copies, read access is only performed in RAM.

> 2) mnesia:add_table_copy(table, node(), disc_copies)
>    This didnt have any effect. Didnt create any disc copy.

No, it is not allowed. (Did you really check the return value?)
You can only have one replica per node. Its storage type is
EITHER ram_copies, disc_copies OR disc_only_copies.
disc_copies implies storage both in RAM AND on disk.

> So, what would be the correct way to
> 1) Load data to RAM as well as backup in disc.
> 2) Queries/ Multiple loads should access/update RAM/disc resp.
> 3) On mnesia restart data should be loaded from Disc automatically.

You will get this behavior if you use the disc_copies storage type.

/Håkan



More information about the erlang-questions mailing list