Mnesia creating table on release startup consistency

at release startup, I’m creating mnesia tables with mnesia:create_table/2. That works however, every second startup all the tables are deleted and created again. To be clear if tables exist it is ok for my case for the call to mnesia:create_table/2 to fail with {aborted, {already_exists, <table name>}} and it is also happening every other startup. Can someone please explain that behavior and what am i doing wrong?

2 Likes

It sounds like tables get created inside a release/build and rebuilding may be removing the database(s).

What you may want to try is to set your mnesia dir for some other location in your vm.args
eg

-mnesia dir '"/var/lib/myapp/mnesia_dir"'

1 Like

my problem is happening without rebuilding, just stopping and restarting the release is enough to reproduce this problem. Also, my mnesia dir is set via sys.config and that seems to create tables in the right place.

1 Like

From the documentation:

Mnesia startup is asynchronous. The function call mnesia:start() returns the atom ok and then starts to initialize the different tables. Depending on the size of the database, this can take some time, and the application programmer must wait for the tables that the application needs before they can be used. This is achieved by using the function mnesia:wait_for_tables/2.

So, the problem could be if you try to initialize new tables without waiting for them to load.

1 Like

It could be helpful if you posted a snippet containing the calls to mnesia:create_table/2 including the parameters that you are using (type of tables, etc.)

By the way, have you created the schema? See the mnesia:create_schema/1 function. And also, are you working with a single node or with a cluster?

2 Likes