11 Mnesia Database Questions

Mnesia is the somewhat odd name for the real-time, distributed database which comes with Erlang.

11.1 What is Mnesia good at?

11.1.1 Locking and Transactions

If you need to keep a database that will be used by multiple processes and/or nodes, using Mnesia means you don't have to write your own access controls.

11.1.2 Distribution

Tables can be replicated at many nodes, both for efficiency (database lookup is a local activity) and robustness (redundancy means if one node goes down, other nodes still have copies of the data.)

11.1.3 Non-fully-normalised data

Unlike most database systems, records can contain data of arbitrary size and structure.

11.1.4 Monitoring

Monitoring - processes can subscribe to events which are sent when various operations on the data take place (update, delete, etc) The RDBMS package allows even more fine-grained control.

11.2 What is Mnesia not so good at?

Mnesia is primarily intended to be a memory-resident database. Some of its design tradeoffs reflect this.

Really large tables must be stored in a fragmented manner.

11.3 Is Mnesia good for storing blobs?

It depends. Erlang has no problem storing Erlang binary data types of arbritary size, however due to the in-memory-database design emphasis of mnesia, storing lots of binary data will eventually hit one of a number of limitations. These are driven by:

As always, measurement of the different mechanisms for your specific application is recommended.

A more colourful discussion of the these topics can be found in this post to the mailing list.

11.4 Is there an SQL interface for mnesia?

A partial one was built as a masters project, it's of limited use and not widely used.

QLC is the query engine for Mnesia and ETS. It is a much better fit to Erlang than SQL.

11.5 How much data can be stored in Mnesia?

Dets uses 32 bit integers for file offsets, so the largest possible mnesia table (for now) is 4Gb.

In practice your machine will slow to a crawl way before you reach this limit.

11.6 Contributors

Thanks to Chris Pressey, Ulf Wiger and Sean Hinde for writing the entries in this section.