Matt
Matt

Reputation: 88157

Why would Mnesia not use the database on disk?

I've got a case where I have a Mnesia database with tables written to the disk. When I stop my app and then restart it, mnesia:info() tells me

opt_disc. Directory "/my/directory/here" is NOT used.

and the corresponding mnesia:system_info(use_dir) is false. But mnesia:system_info(directory) returns the name of the correct directory and the files are there and it was using them just a minute ago. Is there a way to catch that at startup and tell it to use the existing data from disk?

If I check mnesia:table_info(schema, storage_type) it tells me ram_copies. If I then try mnesia:change_table_copy_type() it will write to disk, but ends up squashing all my data.

Upvotes: 1

Views: 915

Answers (2)

Matt
Matt

Reputation: 88157

This was actually due to my own confusion. Our deployment process was wiping out the Mnesia directory and it was getting recreated at startup. So I didn't see it go away, but that's why my data was getting squashed.

use_dir was false, because there was no directory at that point. Then when I ran mnesia:change_table_copy_type() on the schema, it was creating the directory at that point, but it had no data.

Upvotes: 1

Sunil Singh
Sunil Singh

Reputation: 538

you need to do is set Mnesia's dir application variable with something like

application:set_env(mnesia, dir, "/path/to/db").

you can set application variables using release config files or command line arguments.

Upvotes: 1

Related Questions