[erlang-questions] When to create mnesia schema for OTP applications

Paul Mineiro <>
Mon Jun 29 03:32:17 CEST 2009


By the way, just to augment the excellent answers already in this thread,
I don't see the need to call mnesia:create_schema/1 before mnesia is
started.  Fresh mnesias started via mnesia:start/0 begin with ram-based
schemas which can be hooked up to other mnesias via mnesia:change_config/2
with the extra_db_nodes parameter, and then converted to disc based
schemas via mnesia:change_table_copy_type/3.

You can check out the relevant code from schemafinder for inspiration:

http://code.google.com/p/schemafinder/source/browse/trunk/schemafinder/src/schemafindersrv.erl#44

schemafinder essentially does dirty schema reads to avoid creating
unnecessary schema transactions (which slow down node restart times under
heavy load), but the essence of the sequence is: mnesia:start/0,
mnesia:change_config/2, mnesia:change_table_copy_type/3.

-- p

On Sat, 27 Jun 2009, Seth Falcon wrote:

> Hi all,
>
> I have a question about how folks bootstrap an OTP application that
> depends on mnesia.  Consider an OTP application foo that uses mnesia.
> Since mnesia is specified in the needed applications list, mnesia must
> be started before you start foo.
>
> For the first run of foo, one needs to call mnesia:create_schema/1
> _before_ mnesia is started.
>
> I'd like to be able to start foo on a clean system and have the schema
> created if needed, but don't see a way to handle this.  I suspect that
> I need to adjust my expectations :-)
>
> Is there a recommended way to handle mnesia initialization?  Is the
> standard practice to create the schema outside of the application
> start up flow or am I missing a way to handle this as part of foo's
> application initialization?
>
> Thanks,
>
> + seth
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>



More information about the erlang-questions mailing list