ArticleslgStudy

engineering

Mnesia

Mnesia is a engineering topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Mnesia rather than just read about it. In short: Mnesia is a distributed, soft real-time database management system written in the Erlang programming language. It is distributed as part of the Open Telecom Platform.

Mnesia — main illustration
Mnesia — illustration

Key takeaways

  • Mnesia belongs to engineering; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Mnesia to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Mnesia from memory before moving on to harder problems.

Reference excerpt

Mnesia is a distributed, soft real-time database management system written in the Erlang programming language. It is distributed as part of the Open Telecom Platform.

Description As with Erlang, Mnesia was developed by Ericsson for soft real-time distributed and high-availability computing work related to telecoms. It was not intended as a general office-based data processing database management system, nor to replace SQL-based systems. Instead Mnesia exists to support Erlang, where DBMS-like persistence is required. It has more in common with embeddable DBMS such as Berkeley DB than with any SQL database server.

Database model "Rows" in tables are represented as records that contain a key value and a data field. This data field may in turn be a tuple containing an Erlang data structure of any complexity.

Backend types Mnesia has three inbuilt table types: ram_copies, disc_copies and disc_only_copies.

Ram_copies Data resides in memory and table size is limited by available memory and are backed by ETS (erlang term storage) table.

Disc_copies Data resides in memory but is also persisted on disk backed by disk_log. Disc_copies were backed by Dets tables until 30 September 2001 with the release of Erlang R7B-4.

Disc_only_copies Data resides only on disc and are backed by Dets (disk version of ETS). Dets file format uses signed 32-bit integers for file offsets and has a limit of 2 GB so do disc_only_copies.

Backend plugins Due to limits imposed by Dets, support for other backend plugins was suggested by Ulf Wiger and these were added to Mnesia. Klarna added the LevelDB backend plugin while Aeternity added the RocksDB backend plugin.

Relational features The database model is relational, but isn't what someone familiar with SQL might expect. A database contains tables. Relationships between them are modelled as other tables. A key feature of Mnesia's high-availability approach is that tables can be reconfigured within a schema and relocated between nodes, not only while the database is still running, but even while write operations are still going on.

Coding The query language of Mnesia is Erlang itself, rather than SQL. It permits easy representation of transactions as a natural feature of Erlang by allowing developers to utilize a single language throughout an application.

Transactions Erlang is a functional language. Mnesia builds on this to obtain ACID transaction support. The functional block which is run as a transaction is a commonplace Erlang construct called a Functional Object (or Fun) and is called by the single Mnesia statement mnesia:transaction(F). This can lead to clearer source code than the paired BEGIN / COMMIT syntax of SQL, and so avoids its problem of unclosed transactions within a procedure. Again as a result of the functional nature of Erlang, nesting transactions is simple. It's also possible to distribute transactions across multiple nodes (i.e. separate servers). The semantics of using transactions in this way remains consistent, making it easy to write library code that works equally in either context. General coding style for Mnesia will always use transactions. For performance reasons, it also supports deliberate "dirty operations" which avoid transactions. These compromise the atomicity and the isolation properties of ACID, but offer around 10× more throughput. In addition there are also in-memory alternatives, although these lose the durability property of ACID.

Efficient execution Mnesia forms part of the LYME web application stack. This is akin to LAMP, but based on Erlang. Implementation in Erlang confers an efficiency benefit because of the use of a single virtual machine throughout an application. LYME makes use of this, since the Yaws web server is also implemented in Erlang. Address space is shared (although safely so, under Erlang) between code and data, including Mnesia's table data.

Origins and licensing Mnesia and Erlang were developed by the Ericsson Computer Science Laboratory. They have been released as open source software. Mnesia is released under a derivative of the Mozilla Public License. Since OTP 18.0 they are published according to the open source Apache License 2.0. Versions before OTP 18.0 were published under the open source Erlang Public License.

ejabberd Mnesia is also an option embedded within the Erlang-based Jabber daemon, ejabberd.

See also

Riak Apache Cassandra Couchbase CouchDB LYME (software bundle)

References

Illustrations

Mnesia: LYME (software bundle) is based on Erlang and comprises Mnesia. It is entirely composed of free and open-source software
LYME (software bundle) is based on Erlang and comprises Mnesia. It is entirely composed of free and open-source software

Worked examples

Example 1 — a first encounter with Mnesia

Start with the simplest possible case. Write down what Mnesia claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In engineering, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Mnesia before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Mnesia ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Mnesia

In research
Mnesia appears in engineering research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Mnesia in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Mnesia is common in secondary-school and first-year university syllabi. It links to neighbouring topics Erlang (programming language), Free database management systems, Structured storage, so understanding it makes those chapters shorter.
In everyday life
Look for Mnesia outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Mnesia” →

How to study Mnesia in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Mnesia means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Mnesia out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Mnesia in simple terms?

Mnesia is a distributed, soft real-time database management system written in the Erlang programming language. It is distributed as part of the Open Telecom Platform.

Why does Mnesia matter?

Because it connects several engineering ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Mnesia?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Mnesia.

Tags

  • Erlang (programming language)
  • Free database management systems
  • Structured storage

Keep exploring