1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
7
<year>1996</year><year>2009</year>
8
<holder>Ericsson AB. All Rights Reserved.</holder>
11
The contents of this file are subject to the Erlang Public License,
12
Version 1.1, (the "License"); you may not use this file except in
13
compliance with the License. You should have received a copy of the
14
Erlang Public License along with this software. If not, it can be
15
retrieved online at http://www.erlang.org/.
17
Software distributed under the License is distributed on an "AS IS"
18
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19
the License for the specific language governing rights and limitations
25
<prepared>Claes Wikström and Håkan Mattsson</prepared>
26
<responsible></responsible>
34
<module>mnesia</module>
35
<modulesummary>A Distributed Telecommunications DBMS </modulesummary>
37
<p><c>Mnesia</c> is a distributed DataBase Management System (DBMS),
38
appropriate for telecommunications applications and other Erlang
39
applications which require continuous operation and exhibit soft
42
<p>Listed below are some of the most important and attractive capabilities, Mnesia provides:
44
<list type="bulleted">
46
<p>A relational/object hybrid data model which is
47
suitable for telecommunications applications.
51
<p>A specifically designed DBMS query language, QLC (as an add-on library).
55
<p>Persistence. Tables may be coherently kept on disc as
56
well as in main memory.
60
<p>Replication. Tables may be replicated at several nodes.
64
<p>Atomic transactions. A series of table manipulation
65
operations can be grouped into a single atomic
70
<p>Location transparency. Programs can be written without
71
knowledge of the actual location of data.
75
<p>Extremely fast real time data searches.
79
<p>Schema manipulation routines. It is possible to
80
reconfigure the DBMS at runtime without stopping the
85
<p>This Reference Manual describes the Mnesia API. This includes
86
functions used to define and manipulate Mnesia tables.
88
<p>All functions documented in these pages can be used in any
89
combination with queries using the list comprehension notation. The
90
query notation is described in the QLC's man page.
92
<p>Data in Mnesia is organized as a set of tables. Each table
93
has a name which must be an atom. Each table is made up of
94
Erlang records. The user is responsible for the record
95
definitions. Each table also has a set of properties. Below
96
are some of the properties that are associated with each
99
<list type="bulleted">
101
<p><c>type</c>. Each table can either have 'set',
102
'ordered_set' or 'bag' semantics. Note: currently 'ordered_set'
103
is not supported for 'disc_only_copies'. If a table is of type
104
'set' it means that each key leads to either one or zero
106
If a new item is inserted with the same key as
107
an existing record, the old record is overwritten. On the
108
other hand, if a table is of type 'bag', each key can map to
109
several records. However, all records in type bag tables are
110
unique, only the keys may be duplicated.
114
<p><c>record_name</c>. All records stored in a table must
115
have the same name. You may say that the records must be
116
instances of the same record type.
120
<p><c>ram_copies</c> A table can be replicated on a number
121
of Erlang nodes. The <c>ram_copies</c> property specifies a
122
list of Erlang nodes where RAM copies are kept. These
123
copies can be dumped to disc at regular intervals. However,
124
updates to these copies are not written to disc on a
129
<p><c>disc_copies</c> The <c>disc_copies</c> property
130
specifies a list of Erlang nodes where the table is kept in
131
RAM as well as on disc. All updates of the table are
132
performed on the actual table and are also logged to disc.
133
If a table is of type <c>disc_copies</c> at a certain node,
134
it means that the entire table is resident in RAM memory as
135
well as on disc. Each transaction performed on the table is
136
appended to a LOG file as well as written into the RAM
141
<p><c>disc_only_copies</c> Some, or all, table replicas
142
can be kept on disc only. These replicas are considerably
143
slower than the RAM based replicas.
147
<p><c>index</c> This is a list of attribute names, or
148
integers, which specify the tuple positions on which
149
Mnesia shall build and maintain an extra index table.
153
<p><c>local_content</c> When an application requires
154
tables whose contents is local to each node,
155
<c>local_content</c> tables may be used. The name of the
156
table is known to all Mnesia nodes, but its contents is
157
unique on each node. This means that access to such a table
158
must be done locally. Set the <c>local_content</c> field to
159
<c>true</c> if you want to enable the <c>local_content</c>
160
behavior. The default is <c>false</c>.
164
<p><c>snmp</c> Each (set based) Mnesia table can be
165
automatically turned into an SNMP ordered table as well.
166
This property specifies the types of the SNMP keys.
170
<p><c>attributes</c>. The names of the attributes for the
171
records that are inserted in the table.
175
<p>See <c>mnesia:create_table/2</c> about the complete set of
176
table properties and their details.
178
<p>This document uses a table of persons to illustrate various
179
examples. The following record definition is assumed:
182
-record(person, {name,
188
<p>The first attribute of the record is the primary key, or key
191
<p>The function descriptions are sorted in alphabetic order. <em>Hint:</em>
192
start to read about <c>mnesia:create_table/2</c>,
193
<c>mnesia:lock/2</c> and <c>mnesia:activity/4</c> before you continue on
194
and learn about the rest.
196
<p>Writing or deleting in transaction context creates a local copy
197
of each modified record during the transaction. During iteration,
198
i.e. <c>mnesia:fold[lr]/4</c> <c>mnesia:next/2</c> <c>mnesia:prev/2</c>
199
<c>mnesia:snmp_get_next_index/2</c>, mnesia will compensate for
200
every written or deleted record, which may reduce the
201
performance. If possible avoid writing or deleting records in
202
the same transaction before iterating over the table.
207
<name>abort(Reason) -> transaction abort </name>
208
<fsummary>Abort the current transaction.</fsummary>
210
<p>Makes the transaction silently
211
return the tuple <c>{aborted, Reason}</c>.
212
The abortion of a Mnesia transaction means that
213
an exception will be thrown to an enclosing <c>catch</c>.
214
Thus, the expression <c>catch mnesia:abort(x)</c> does
215
not abort the transaction. </p>
219
<name>activate_checkpoint(Args) -> {ok,Name,Nodes} | {error,Reason}</name>
220
<fsummary>Activate a checkpoint.</fsummary>
222
<p>A checkpoint is a consistent view of the system.
223
A checkpoint can be activated on a set of tables.
224
This checkpoint can then be traversed and will
225
present a view of the system as it existed at the time when
226
the checkpoint was activated, even if the tables are being or have been
229
<p><c>Args</c> is a list of the following tuples:
231
<list type="bulleted">
233
<p><c>{name,Name}</c>. <c>Name</c> of checkpoint. Each
234
checkpoint must have a name which is unique to the
235
associated nodes. The name can be reused only once the
236
checkpoint has been deactivated. By default, a name
237
which is probably unique is generated.
241
<p><c>{max,MaxTabs}</c><c>MaxTabs</c> is a list of
242
tables that should be included in the checkpoint. The
243
default is []. For these tables, the redundancy will be
244
maximized and checkpoint information will be retained together
245
with all replicas. The checkpoint becomes more fault
246
tolerant if the tables have several replicas. When a new
247
replica is added by means of the schema manipulation
248
function <c>mnesia:add_table_copy/3</c>, a retainer will
249
also be attached automatically.
253
<p><c>{min,MinTabs}</c>. <c>MinTabs</c> is a list of
254
tables that should be included in the checkpoint. The
255
default is []. For these tables, the redundancy will be
256
minimized and the checkpoint information will only be retained
257
with one replica, preferably on the local node.
261
<p><c>{allow_remote,Bool}</c>. <c>false</c> means that
262
all retainers must be local. The checkpoint cannot be
263
activated if a table does not reside locally.
264
<c>true</c> allows retainers to be allocated on any
265
node. Default is set to <c>true</c>.
269
<p><c>{ram_overrides_dump,Bool} </c> Only applicable
270
for <c>ram_copies</c>. <c>Bool</c> allows you to choose
271
to backup the table state as it is in RAM, or as it is on
272
disc. <c>true</c> means that the latest committed
273
records in RAM should be included in the checkpoint.
274
These are the records that the application accesses.
275
<c>false</c> means that the records dumped to DAT files
276
should be included in the checkpoint. These are the
277
records that will be loaded at startup. Default is
282
<p>Returns <c>{ok,Name,Nodes}</c> or <c>{error,Reason}</c>.
283
<c>Name</c> is the (possibly generated) name of the
284
checkpoint. <c>Nodes</c> are the nodes that
285
are involved in the checkpoint. Only nodes that keep a
286
checkpoint retainer know about the checkpoint.
291
<name>activity(AccessContext, Fun [, Args]) -> ResultOfFun | exit(Reason)</name>
292
<fsummary>Execute <c>Fun</c>in <c>AccessContext</c>.</fsummary>
294
<p>Invokes <c>mnesia:activity(AccessContext, Fun, Args, AccessMod)</c> where <c>AccessMod</c> is the default
295
access callback module obtained by
296
<c>mnesia:system_info(access_module)</c>. <c>Args</c>
297
defaults to the empty list <c>[]</c>.</p>
301
<name>activity(AccessContext, Fun, Args, AccessMod) -> ResultOfFun | exit(Reason)</name>
302
<fsummary>Execute <c>Fun</c>in <c>AccessContext</c>.</fsummary>
304
<p>This function executes the functional object <c>Fun</c>
305
with the arguments <c>Args</c>.
307
<p>The code which executes inside the activity can
308
consist of a series of table manipulation functions, which is
309
performed in a <c>AccessContext</c>. Currently, the following
310
access contexts are supported:
313
<tag><c>transaction</c></tag>
315
<p>Short for <c>{transaction, infinity}</c></p>
317
<tag><c>{transaction, Retries}</c></tag>
319
<p>Invokes <c>mnesia:transaction(Fun, Args, Retries)</c>. Note that the result from the <c>Fun</c> is
320
returned if the transaction was successful (atomic),
321
otherwise the function exits with an abort reason.
324
<tag><c>sync_transaction</c></tag>
326
<p>Short for <c>{sync_transaction, infinity}</c></p>
328
<tag><c>{sync_transaction, Retries}</c></tag>
330
<p>Invokes <c>mnesia:sync_transaction(Fun, Args, Retries)</c>. Note that the result from the <c>Fun</c> is
331
returned if the transaction was successful (atomic),
332
otherwise the function exits with an abort reason.
335
<tag><c>async_dirty</c></tag>
337
<p>Invokes <c>mnesia:async_dirty(Fun, Args)</c>.
340
<tag><c>sync_dirty</c></tag>
342
<p>Invokes <c>mnesia:sync_dirty(Fun, Args)</c>.
345
<tag><c>ets</c></tag>
347
<p>Invokes <c>mnesia:ets(Fun, Args)</c>.
351
<p>This function (<c>mnesia:activity/4</c>) differs in an
352
important aspect from the <c>mnesia:transaction</c>,
353
<c>mnesia:sync_transaction</c>,
354
<c>mnesia:async_dirty</c>, <c>mnesia:sync_dirty</c> and
355
<c>mnesia:ets</c> functions. The <c>AccessMod</c> argument
356
is the name of a callback module which implements the
357
<c>mnesia_access</c> behavior.
359
<p>Mnesia will forward calls to the following functions:
361
<list type="bulleted">
363
<p>mnesia:write/3 (write/1, s_write/1)</p>
366
<p>mnesia:delete/3 (delete/1, s_delete/1)</p>
369
<p>mnesia:delete_object/3 (delete_object/1, s_delete_object/1)</p>
372
<p>mnesia:read/3 (read/1, wread/1)</p>
375
<p>mnesia:match_object/3 (match_object/1)</p>
378
<p>mnesia:all_keys/1</p>
381
<p>mnesia:first/1</p>
393
<p>mnesia:index_match_object/4 (index_match_object/2)</p>
396
<p>mnesia:index_read/3</p>
399
<p>mnesia:lock/2 (read_lock_table/1, write_lock_table/1)</p>
402
<p>mnesia:table_info/2</p>
405
<p>to the corresponding:
407
<list type="bulleted">
409
<p>AccessMod:lock(ActivityId, Opaque, LockItem, LockKind)</p>
412
<p>AccessMod:write(ActivityId, Opaque, Tab, Rec, LockKind)</p>
415
<p>AccessMod:delete(ActivityId, Opaque, Tab, Key, LockKind)</p>
418
<p>AccessMod:delete_object(ActivityId, Opaque, Tab, RecXS, LockKind)</p>
421
<p>AccessMod:read(ActivityId, Opaque, Tab, Key, LockKind)</p>
424
<p>AccessMod:match_object(ActivityId, Opaque, Tab, Pattern, LockKind)</p>
427
<p>AccessMod:all_keys(ActivityId, Opaque, Tab, LockKind)</p>
430
<p>AccessMod:first(ActivityId, Opaque, Tab)</p>
433
<p>AccessMod:last(ActivityId, Opaque, Tab)</p>
436
<p>AccessMod:prev(ActivityId, Opaque, Tab, Key)</p>
439
<p>AccessMod:next(ActivityId, Opaque, Tab, Key)</p>
442
<p>AccessMod:index_match_object(ActivityId, Opaque, Tab, Pattern, Attr, LockKind)</p>
445
<p>AccessMod:index_read(ActivityId, Opaque, Tab, SecondaryKey, Attr, LockKind)</p>
448
<p>AccessMod:table_info(ActivityId, Opaque, Tab, InfoItem)</p>
451
<p>where <c>ActivityId</c> is a record which represents the
452
identity of the enclosing Mnesia activity. The first field
453
(obtained with <c>element(1, ActivityId)</c> contains an
454
atom which may be interpreted as the type of the activity:
455
<c>'ets'</c>, <c>'async_dirty'</c>, <c>'sync_dirty'</c> or
456
<c>'tid'</c>. <c>'tid'</c> means that the activity is a
457
transaction. The structure of the rest of the identity
458
record is internal to Mnesia.
460
<p><c>Opaque</c> is an opaque data structure which is internal
465
<name>add_table_copy(Tab, Node, Type) -> {aborted, R} | {atomic, ok}</name>
466
<fsummary>Copy a table to a remote node.</fsummary>
468
<p>This function makes another copy of a table at the
469
node <c>Node</c>. The <c>Type</c> argument must be
470
either of the atoms <c>ram_copies</c>, <c>disc_copies</c>,
472
<c>disc_only_copies</c>. For example, the following call
473
ensures that a disc replica of the <c>person</c> table also
474
exists at node <c>Node</c>.</p>
476
mnesia:add_table_copy(person, Node, disc_copies)
478
<p>This function can also be used to add a replica of the
479
table named <c>schema</c>.</p>
483
<name>add_table_index(Tab, AttrName) -> {aborted, R} | {atomic, ok}</name>
484
<fsummary>Create an index for a table. </fsummary>
486
<p>Table indices can and should be used whenever the user
487
wants to frequently use some other field than the key field
488
to look up records. If this other field has an index
489
associated with it, these lookups can occur in constant time
490
and space. For example, if our application wishes to use
491
the age field of persons to efficiently find all person with
492
a specific age, it might be a good idea to have an index on
493
the age field. This can be accomplished with the following
496
mnesia:add_table_index(person, age)
498
<p>Indices do not come free, they occupy space which is
499
proportional to the size of the table. They also cause insertions
500
into the table to execute slightly slower. </p>
504
<name>all_keys(Tab) -> KeyList | transaction abort</name>
505
<fsummary>Return all keys in a table.</fsummary>
507
<p>This function returns a list of all keys in the table
508
named <c>Tab</c>. The semantics of this function is context
509
sensitive. See <c>mnesia:activity/4</c> for more information. In
510
transaction context it acquires a read lock on the entire
515
<name>async_dirty(Fun, [, Args]) -> ResultOfFun | exit(Reason)</name>
516
<fsummary>Call the Fun in a context which is not protected by a transaction.</fsummary>
518
<p>Call the <c>Fun</c> in a context which is not protected
519
by a transaction. The Mnesia function calls performed in the
520
<c>Fun</c> are mapped to the corresponding dirty
521
functions. This still involves logging, replication and
522
subscriptions, but there is no locking, local transaction
523
storage, or commit protocols involved. Checkpoint retainers
524
and indices are updated, but they will be updated dirty. As
525
for normal mnesia:dirty_* operations, the operations are
526
performed semi-asynchronously. See
527
<c>mnesia:activity/4</c> and the Mnesia User's Guide for
530
<p>It is possible to manipulate the Mnesia tables without
531
using transactions. This has some serious disadvantages, but
532
is considerably faster since the transaction manager is not
533
involved and no locks are set. A dirty operation does,
534
however, guarantee a certain level of consistency and it is
535
not possible for the dirty operations to return garbled
536
records. All dirty operations provide location transparency
537
to the programmer and a program does not have to be aware of
538
the whereabouts of a certain table in order to function.
540
<p><em>Note:</em>It is more than 10 times more efficient to read records dirty
541
than within a transaction.
543
<p>Depending on the application, it may be a good idea to use
544
the dirty functions for certain operations. Almost all
545
Mnesia functions which can be called within transactions
546
have a dirty equivalent which is much more
547
efficient. However, it must be noted that it is possible for
548
the database to be left in an inconsistent state if dirty
549
operations are used to update it. Dirty operations should
550
only be used for performance reasons when it is absolutely
552
<p><em>Note:</em> Calling (nesting) a <c>mnesia:[a]sync_dirty</c>
553
inside a transaction context will inherit the transaction semantics.
558
<name>backup(Opaque [, BackupMod]) -> ok | {error,Reason}</name>
559
<fsummary>Back up all tables in the database.</fsummary>
561
<p>Activates a new checkpoint covering all Mnesia tables,
562
including the schema, with maximum degree of redundancy and
563
performs a backup using <c>backup_checkpoint/2/3</c>. The
564
default value of the backup callback module <c>BackupMod</c>
565
is obtained by <c>mnesia:system_info(backup_module)</c>.</p>
569
<name>backup_checkpoint(Name, Opaque [, BackupMod]) -> ok | {error,Reason}</name>
570
<fsummary>Back up all tables in a checkpoint.</fsummary>
572
<p>The tables are backed up to external media using the backup
573
module <c>BackupMod</c>. Tables with the local contents
574
property is being backed up as they exist on the current
575
node. <c>BackupMod</c> is the default backup callback
577
<c>mnesia:system_info(backup_module)</c>. See the User's
578
Guide about the exact callback interface (the
579
<c>mnesia_backup behavior</c>).</p>
583
<name>change_config(Config, Value) -> {error, Reason} | {ok, ReturnValue}</name>
584
<fsummary>Change a configuration parameter.</fsummary>
586
<p>The <c>Config</c> should be an atom of the following
587
configuration parameters: </p>
589
<tag><c>extra_db_nodes</c></tag>
591
<p><c>Value</c> is a list of nodes which Mnesia should try to connect to.
592
The <c>ReturnValue</c> will be those nodes in
593
<c>Value</c> that Mnesia are connected to.
595
Note: This function shall only be used to connect to newly started ram nodes
596
(N.D.R.S.N.) with an empty schema. If for example it is used after the network
597
have been partitioned it may lead to inconsistent tables.
599
Note: Mnesia may be connected to other nodes than those
600
returned in <c>ReturnValue</c>.</p>
602
<tag><c>dc_dump_limit</c></tag>
604
<p><c>Value</c> is a number. See description in
605
<c>Configuration Parameters</c> below.
606
The <c>ReturnValue</c> is the new value. Note this configuration parameter
607
is not persistent, it will be lost when mnesia stopped.</p>
613
<name>change_table_access_mode(Tab, AccessMode) -> {aborted, R} | {atomic, ok}</name>
614
<fsummary>Change the access mode for the table.</fsummary>
616
<p>The <c>AcccessMode</c> is by default the atom
617
<c>read_write</c> but it may also be set to the atom
618
<c>read_only</c>. If the <c>AccessMode</c> is set to
619
<c>read_only</c>, it means that it is not possible to perform
620
updates to the table. At startup Mnesia always loads
621
<c>read_only</c> tables locally regardless of when and if
622
Mnesia was terminated on other nodes.</p>
626
<name>change_table_copy_type(Tab, Node, To) -> {aborted, R} | {atomic, ok}</name>
627
<fsummary>Change the storage type of a table.</fsummary>
631
mnesia:change_table_copy_type(person, node(), disc_copies)
633
<p>Transforms our <c>person</c> table from a RAM table into
634
a disc based table at <c>Node</c>.
636
<p>This function can also be used to change the storage type of
637
the table named <c>schema</c>. The schema table can only
638
have <c>ram_copies</c> or <c>disc_copies</c> as the storage type. If the
639
storage type of the schema is <c>ram_copies</c>, no other table
640
can be disc resident on that node.</p>
644
<name>change_table_load_order(Tab, LoadOrder) -> {aborted, R} | {atomic, ok}</name>
645
<fsummary>Change the load order priority for the table.</fsummary>
647
<p>The <c>LoadOrder</c> priority is by default <c>0</c> (zero)
648
but may be set to any integer. The tables with the highest
649
<c>LoadOrder</c> priority will be loaded first at startup.</p>
653
<name>clear_table(Tab) -> {aborted, R} | {atomic, ok}</name>
654
<fsummary>Deletes all entries in a table.</fsummary>
656
<p>Deletes all entries in the table <c>Tab</c>.</p>
660
<name>create_schema(DiscNodes) -> ok | {error,Reason}</name>
661
<fsummary>Create a brand new schema on the specified nodes.</fsummary>
663
<p>Creates a new database on disc. Various files are
664
created in the local Mnesia directory of each node. Note
665
that the directory must be unique for each node. Two nodes
666
may never share the same directory. If possible, use a local
667
disc device in order to improve performance.</p>
668
<p><c>mnesia:create_schema/1</c> fails if any of the
669
Erlang nodes given as <c>DiscNodes</c> are not alive, if
670
Mnesia is running on anyone of the nodes, or if anyone of
671
the nodes already has a schema. Use
672
<c>mnesia:delete_schema/1</c> to get rid of old faulty
675
<p><em>Note:</em> Only nodes with disc should be
676
included in <c>DiscNodes</c>. Disc-less nodes, that is nodes
677
where all tables including the schema only resides in RAM,
678
may not be included.</p>
682
<name>create_table(Name, TabDef) -> {atomic, ok} | {aborted, Reason}</name>
683
<fsummary>Create a Mnesia table called <c>Name</c>with properties as described by the argument <c>TabDef</c>.</fsummary>
685
<p>This function creates a Mnesia table called <c>Name</c>
687
argument <c>TabDef</c>. This list must be a list of
688
<c>{Item, Value}</c> tuples, where the following values are
690
<list type="bulleted">
692
<p><c>{access_mode, Atom}</c>. The access mode is by
693
default the atom <c>read_write</c> but it may also be
694
set to the atom <c>read_only</c>. If the
695
<c>AccessMode</c> is set to <c>read_only</c>, it means
696
that it is not possible to perform updates to the table.
698
<p>At startup Mnesia always loads <c>read_only</c> tables
699
locally regardless of when and if Mnesia was terminated
700
on other nodes. This argument returns the access mode of
701
the table. The access mode may either be read_only or
706
<p><c>{attributes, AtomList}</c> a list of the
707
attribute names for the records that are supposed to
708
populate the table. The default value is <c>[key, val]</c>. The table must have at least one extra
709
attribute in addition to the key.
711
<p>When accessing single attributes in a record, it is not
712
necessary, or even recommended, to hard code any
713
attribute names as atoms. Use the construct
714
<c>record_info(fields, RecordName)</c> instead. It can be
715
used for records of type <c>RecordName</c></p>
718
<p><c>{disc_copies, Nodelist}</c>, where
719
<c>Nodelist</c> is a list of the nodes where this table
720
is supposed to have disc copies. If a table replica is
721
of type <c>disc_copies</c>, all write operations on this
722
particular replica of the table are written to disc as
723
well as to the RAM copy of the table.
726
to have a replicated table of type <c>disc_copies</c>
727
on one node, and another type on another node. The
728
default value is <c>[]</c></p>
731
<p><c>{disc_only_copies, Nodelist}</c>, where
732
<c>Nodelist</c> is a list of the nodes where this table
733
is supposed to have <c>disc_only_copies</c>. A disc only
734
table replica is kept on disc only and unlike the other
735
replica types, the contents of the replica will not
736
reside in RAM. These replicas are considerably slower
737
than replicas held in RAM.
741
<p><c>{index, Intlist}</c>, where
742
<c>Intlist</c> is a list of attribute names (atoms) or
743
record fields for which Mnesia shall build and maintain
744
an extra index table. The <c>qlc</c> query compiler may
745
or may not utilize any additional indices while
746
processing queries on a table.
750
<p><c>{load_order, Integer}</c>. The load order
751
priority is by default <c>0</c> (zero) but may be set to
752
any integer. The tables with the highest load order
753
priority will be loaded first at startup.
757
<p><c>{ram_copies, Nodelist}</c>, where
758
<c>Nodelist</c> is a list of the nodes where this table
759
is supposed to have RAM copies. A table replica of type
760
<c>ram_copies</c> is obviously not written to disc on a
761
per transaction basis. It is possible to dump
762
<c>ram_copies</c> replicas to disc with the function
763
<c>mnesia:dump_tables(Tabs)</c>. The default value for
764
this attribute is <c>[node()]</c>.
768
<p><c>{record_name, Name}</c>, where <c>Name</c> must
769
be an atom. All records, stored in the table, must have
770
this name as the first element. It defaults to the same
771
name as the name of the table.
775
<p><c>{snmp, SnmpStruct}</c>. See
776
<c>mnesia:snmp_open_table/2</c> for a description of
777
<c>SnmpStruct</c>. If this attribute is present in the
778
<c>ArgList</c> to <c>mnesia:create_table/2</c>, the
779
table is immediately accessible by means of the Simple
780
Network Management Protocol (SNMP). This means that
781
applications which use SNMP to manipulate and control
782
the system can be designed easily, since Mnesia provides
783
a direct mapping between the logical tables that make up
784
an SNMP control application and the physical data which
785
makes up a Mnesia table.
789
<p><c>{type, Type}</c>, where <c>Type</c> must be
790
either of the atoms <c>set</c>, <c>ordered_set</c> or
791
<c>bag</c>. The default value is <c>set</c>. In a
792
<c>set</c> all records have unique keys and in a
793
<c>bag</c> several records may have the same key, but
794
the record content is unique. If a non-unique record is
795
stored the old, conflicting record(s) will simply be
796
overwritten. Note: currently 'ordered_set'
797
is not supported for 'disc_only_copies'.
801
<p><c>{local_content, Bool}</c>, where <c>Bool</c> must be
802
either <c>true</c> or <c>false</c>. The default value is <c>false</c>.\011 </p>
805
<p>For example, the following call creates the <c>person</c> table
806
previously defined and replicates it on 2 nodes:
809
mnesia:create_table(person,
810
[{ram_copies, [N1, N2]},
811
{attributes, record_info(fields,person)}]).
813
<p>If it was required that Mnesia build and maintain an extra index
814
table on the <c>address</c> attribute of all the <c>person</c>
815
records that are inserted in the table, the following code would be issued:
818
mnesia:create_table(person,
819
[{ram_copies, [N1, N2]},
821
{attributes, record_info(fields,person)}]).
823
<p>The specification of <c>index</c> and <c>attributes</c> may be
824
hard coded as <c>{index, [2]}</c> and
825
<c>{attributes, [name, age, address, salary, children]}</c>
828
<p><c>mnesia:create_table/2</c> writes records into the
829
<c>schema</c> table. This function, as well as all other
830
schema manipulation functions, are implemented with the
831
normal transaction management system. This guarantees that
832
schema updates are performed on all nodes in an atomic
837
<name>deactivate_checkpoint(Name) -> ok | {error, Reason}</name>
838
<fsummary>Deactivate a checkpoint.</fsummary>
840
<p>The checkpoint is automatically deactivated when some of
841
the tables involved have no retainer attached to them. This may
842
happen when nodes go down or when a replica is deleted.
843
Checkpoints will also be deactivated with this function.
844
<c>Name</c> is the name of an active checkpoint.</p>
848
<name>del_table_copy(Tab, Node) -> {aborted, R} | {atomic, ok}</name>
849
<fsummary>Delete the replica of table <c>Tab</c>at node <c>Node</c>.</fsummary>
851
<p>Deletes the replica of table <c>Tab</c> at node <c>Node</c>.
852
When the last replica is deleted with this
853
function, the table disappears entirely.
855
<p>This function may also be used to delete a replica of
856
the table named <c>schema</c>. Then the mnesia node will be removed.
857
Note: Mnesia must be stopped on the node first.</p>
861
<name>del_table_index(Tab, AttrName) -> {aborted, R} | {atomic, ok}</name>
862
<fsummary>Delete an index in a table. </fsummary>
864
<p>This function deletes the index on attribute with name
865
<c>AttrName</c> in a table.</p>
869
<name>delete({Tab, Key}) -> transaction abort | ok </name>
870
<fsummary>Delete all records in table <c>Tab</c>with the key <c>Key</c>.</fsummary>
872
<p>Invokes <c>mnesia:delete(Tab, Key, write)</c></p>
876
<name>delete(Tab, Key, LockKind) -> transaction abort | ok </name>
877
<fsummary>Delete all records in table <c>Tab</c>with the key <c>Key</c>.</fsummary>
879
<p>Deletes all records in table <c>Tab</c> with the key
882
<p>The semantics of this function is context sensitive. See
883
<c>mnesia:activity/4</c> for more information. In transaction
884
context it acquires a lock of type <c>LockKind</c> in the
885
record. Currently the lock types <c>write</c> and
886
<c>sticky_write</c> are supported.</p>
890
<name>delete_object(Record) -> transaction abort | ok </name>
891
<fsummary>Delete a record</fsummary>
893
<p>Invokes <c>mnesia:delete_object(Tab, Record, write)</c> where
894
<c>Tab</c> is <c>element(1, Record)</c>.</p>
898
<name>delete_object(Tab, Record, LockKind) -> transaction abort | ok </name>
899
<fsummary>Delete a record</fsummary>
901
<p>If a table is of type <c>bag</c>, we may sometimes
902
want to delete only some of the records with a certain
903
key. This can be done with the <c>delete_object/3</c>
904
function. A complete record must be supplied to this
907
<p>The semantics of this function is context sensitive. See
908
<c>mnesia:activity/4</c> for more information. In transaction
909
context it acquires a lock of type <c>LockKind</c> on the
910
record. Currently the lock types <c>write</c> and
911
<c>sticky_write</c> are supported.</p>
915
<name>delete_schema(DiscNodes) -> ok | {error,Reason}</name>
916
<fsummary>Delete the schema on the given nodes</fsummary>
918
<p>Deletes a database created with
919
<c>mnesia:create_schema/1</c>.
920
<c>mnesia:delete_schema/1</c> fails if any of the Erlang
921
nodes given as <c>DiscNodes</c> is not alive, or if Mnesia
922
is running on any of the nodes.
924
<p>After the database has been deleted, it may still be
925
possible to start Mnesia as a disc-less node. This depends on
926
how the configuration parameter <c>schema_location</c> is set.
929
<p>This function must be used with extreme
930
caution since it makes existing persistent data
931
obsolete. Think twice before using it. </p>
936
<name>delete_table(Tab) -> {aborted, Reason} | {atomic, ok} </name>
937
<fsummary>Delete permanently all replicas of table <c>Tab</c>.</fsummary>
939
<p>Permanently deletes all replicas of table <c>Tab</c>.</p>
943
<name>dirty_all_keys(Tab) -> KeyList | exit({aborted, Reason}).</name>
944
<fsummary>Dirty search for all record keys in table.</fsummary>
946
<p>This is the dirty equivalent of the
947
<c>mnesia:all_keys/1</c> function.</p>
951
<name>dirty_delete({Tab, Key}) -> ok | exit({aborted, Reason}) </name>
952
<fsummary>Dirty delete of a record.</fsummary>
954
<p>Invokes <c>mnesia:dirty_delete(Tab, Key)</c>.</p>
958
<name>dirty_delete(Tab, Key) -> ok | exit({aborted, Reason}) </name>
959
<fsummary>Dirty delete of a record. </fsummary>
961
<p>This is the dirty equivalent of the
962
<c>mnesia:delete/3</c> function.</p>
966
<name>dirty_delete_object(Record) </name>
967
<fsummary>Dirty delete of a record.</fsummary>
969
<p>Invokes <c>mnesia:dirty_delete_object(Tab, Record)</c>
970
where <c>Tab</c> is <c>element(1, Record)</c>.</p>
974
<name>dirty_delete_object(Tab, Record) </name>
975
<fsummary>Dirty delete of a record. </fsummary>
977
<p>This is the dirty equivalent of the
978
<c>mnesia:delete_object/3</c> function.</p>
982
<name>dirty_first(Tab) -> Key | exit({aborted, Reason}) </name>
983
<fsummary>Return the key for the first record in a table.</fsummary>
985
<p>Records in <c>set</c> or <c>bag</c> tables are not ordered.
987
is an ordering of the records which is not known
988
to the user. Accordingly, it is possible to traverse a table by means
989
of this function in conjunction with the <c>mnesia:dirty_next/2</c>
992
<p>If there are no records at all in the table, this function
993
returns the atom <c>'$end_of_table'</c>. For this reason, it
994
is highly undesirable, but not disallowed, to use this atom
995
as the key for any user records.</p>
999
<name>dirty_index_match_object(Pattern, Pos)</name>
1000
<fsummary>Dirty pattern match using index.</fsummary>
1002
<p>Invokes <c>mnesia:dirty_index_match_object(Tab, Pattern, Pos)</c> where <c>Tab</c> is <c>element(1, Pattern)</c>.</p>
1006
<name>dirty_index_match_object(Tab, Pattern, Pos)</name>
1007
<fsummary>Dirty pattern match using index.</fsummary>
1009
<p>This is the dirty equivalent of the
1010
<c>mnesia:index_match_object/4</c> function.</p>
1014
<name>dirty_index_read(Tab, SecondaryKey, Pos)</name>
1015
<fsummary>Dirty read using index.</fsummary>
1017
<p>This is the dirty equivalent of the
1018
<c>mnesia:index_read/3</c> function.</p>
1022
<name>dirty_last(Tab) -> Key | exit({aborted, Reason}) </name>
1023
<fsummary>Return the key for the last record in a table.</fsummary>
1025
<p>This function works exactly
1026
<c>mnesia:dirty_first/1</c> but returns the last object in
1027
Erlang term order for the <c>ordered_set</c> table type. For
1028
all other table types, <c>mnesia:dirty_first/1</c> and
1029
<c>mnesia:dirty_last/1</c> are synonyms.</p>
1033
<name>dirty_match_object(Pattern) -> RecordList | exit({aborted, Reason}).</name>
1034
<fsummary>Dirty pattern match pattern.</fsummary>
1036
<p>Invokes <c>mnesia:dirty_match_object(Tab, Pattern)</c>
1037
where <c>Tab</c> is <c>element(1, Pattern)</c>.</p>
1041
<name>dirty_match_object(Tab, Pattern) -> RecordList | exit({aborted, Reason}).</name>
1042
<fsummary>Dirty pattern match pattern.</fsummary>
1044
<p>This is the dirty equivalent of the
1045
<c>mnesia:match_object/3</c> function.</p>
1049
<name>dirty_next(Tab, Key) -> Key | exit({aborted, Reason}) </name>
1050
<fsummary>Return the next key in a table. </fsummary>
1052
<p>This function makes it possible to traverse a table
1053
and perform operations on all records in the table. When
1054
the end of the table is reached, the special key
1055
<c>'$end_of_table'</c> is returned. Otherwise, the function
1056
returns a key which can be used to read the actual record.The
1057
behavior is undefined if another Erlang process performs write
1058
operations on the table while it is being traversed with the
1059
<c>mnesia:dirty_next/2</c> function.</p>
1063
<name>dirty_prev(Tab, Key) -> Key | exit({aborted, Reason}) </name>
1064
<fsummary>Return the previous key in a table. </fsummary>
1066
<p>This function works exactly
1067
<c>mnesia:dirty_next/2</c> but returns the previous object in
1068
Erlang term order for the ordered_set table type. For
1069
all other table types, <c>mnesia:dirty_next/2</c> and
1070
<c>mnesia:dirty_prev/2</c> are synonyms.\011 </p>
1074
<name>dirty_read({Tab, Key}) -> ValueList | exit({aborted, Reason}</name>
1075
<fsummary>Dirty read of records.</fsummary>
1077
<p>Invokes <c>mnesia:dirty_read(Tab, Key)</c>.</p>
1081
<name>dirty_read(Tab, Key) -> ValueList | exit({aborted, Reason}</name>
1082
<fsummary>Dirty read of records.</fsummary>
1084
<p>This is the dirty equivalent of the
1085
<c>mnesia:read/3</c> function.</p>
1089
<name>dirty_select(Tab, MatchSpec) -> ValueList | exit({aborted, Reason}</name>
1090
<fsummary>Dirty match the objects in <c>Tab</c>against <c>MatchSpec</c>.</fsummary>
1092
<p>This is the dirty equivalent of the
1093
<c>mnesia:select/2</c> function.</p>
1097
<name>dirty_slot(Tab, Slot) -> RecordList | exit({aborted, Reason})</name>
1098
<fsummary>Return the list of records that are associated with Slot in a table.</fsummary>
1100
<p>This function can be used to traverse a table in a
1101
manner similar to the <c>mnesia:dirty_next/2</c> function.
1102
A table has a number of slots which range from 0 (zero) to some
1103
unknown upper bound. The function
1104
<c>mnesia:dirty_slot/2</c> returns the special atom
1105
<c>'$end_of_table'</c> when the end of the table is reached.
1106
The behavior of this function is undefined if a write
1107
operation is performed on the table while it is being
1112
<name>dirty_update_counter({Tab, Key}, Incr) -> NewVal | exit({aborted, Reason})</name>
1113
<fsummary>Dirty update of a counter record.</fsummary>
1115
<p>Invokes <c>mnesia:dirty_update_counter(Tab, Key, Incr)</c>.</p>
1119
<name>dirty_update_counter(Tab, Key, Incr) -> NewVal | exit({aborted, Reason})</name>
1120
<fsummary>Dirty update of a counter record.</fsummary>
1122
<p>There are no special counter records in Mnesia. However,
1123
records of the form <c>{Tab, Key, Integer}</c> can be used
1124
as (possibly disc resident) counters, when <c>Tab</c> is a
1125
<c>set</c>. This function updates a counter with a
1126
positive or negative number. However, counters can never become less
1127
than zero. There are two significant differences between
1128
this function and the action of first reading the record,
1129
performing the arithmetics, and then writing the record:</p>
1130
<list type="bulleted">
1131
<item>It is much more efficient</item>
1132
<item><c>mnesia:dirty_update_counter/3</c> is
1133
performed as an atomic operation despite the fact that it is not
1134
protected by a transaction.</item>
1136
<p>If two processes perform <c>mnesia:dirty_update_counter/3</c>
1137
simultaneously, both updates will take effect without the
1138
risk of loosing one of the updates. The new value
1139
<c>NewVal</c> of the counter is returned.</p>
1140
<p>If <c>Key</c> don't exits, a new record is created with the value
1141
<c>Incr</c> if it is larger than 0, otherwise it is set to 0.</p>
1145
<name>dirty_write(Record) -> ok | exit({aborted, Reason})</name>
1146
<fsummary>Dirty write of a record.</fsummary>
1148
<p>Invokes <c>mnesia:dirty_write(Tab, Record)</c>
1149
where <c>Tab</c> is <c>element(1, Record)</c>.</p>
1153
<name>dirty_write(Tab, Record) -> ok | exit({aborted, Reason})</name>
1154
<fsummary>Dirty write of a record.</fsummary>
1156
<p>This is the dirty equivalent of <c>mnesia:write/3</c>.</p>
1160
<name>dump_log() -> dumped</name>
1161
<fsummary>Perform a user initiated dump of the local log file.</fsummary>
1163
<p>Performs a user initiated dump of the local log file.
1164
This is usually not necessary since Mnesia, by default,
1165
manages this automatically.</p>
1169
<name>dump_tables(TabList) -> {atomic, ok} | {aborted, Reason}</name>
1170
<fsummary>Dump all RAM tables to disc.</fsummary>
1172
<p>This function dumps a set of <c>ram_copies</c> tables
1173
to disc. The next time the system is started, these tables
1174
are initiated with the data found in the files that are the
1175
result of this dump. None of the tables may have disc
1176
resident replicas.</p>
1180
<name>dump_to_textfile(Filename) </name>
1181
<fsummary>Dump local tables into a text file.</fsummary>
1183
<p>Dumps all local tables of a mnesia system into a text file
1184
which can then be edited (by means of a normal text editor)
1185
and then later be reloaded with
1186
<c>mnesia:load_textfile/1</c>. Only use this function for
1187
educational purposes. Use other functions to deal with real
1192
<name>error_description(Error) -> String </name>
1193
<fsummary>Return a string describing a particular Mnesia error.</fsummary>
1195
<p>All Mnesia transactions, including all the schema
1196
update functions, either return the value <c>{atomic, Val}</c> or the tuple <c>{aborted, Reason}</c>. The
1197
<c>Reason</c> can be either of the following atoms. The
1198
<c>error_description/1</c> function returns a descriptive
1199
string which describes the error.
1201
<list type="bulleted">
1203
<p><c>nested_transaction</c>. Nested transactions are
1204
not allowed in this context.
1208
<p><c>badarg</c>. Bad or invalid argument, possibly
1213
<p><c>no_transaction</c>. Operation not allowed
1214
outside transactions.
1218
<p><c>combine_error</c>. Table options were illegally
1223
<p><c>bad_index</c>. Index already exists or was out
1228
<p><c>already_exists</c>. Schema option is already set.
1232
<p><c>index_exists</c>. Some operations cannot be performed on
1237
<p><c>no_exists</c>. Tried to perform operation on
1238
non-existing, or not alive, item.
1242
<p><c>system_limit</c>. Some system_limit was exhausted.
1246
<p><c>mnesia_down</c>. A transaction involving
1247
records at some remote node which died while
1248
transaction was executing. Record(s) are no longer
1249
available elsewhere in the network.
1253
<p><c>not_a_db_node</c>. A node which does not exist
1254
in the schema was mentioned.
1258
<p><c>bad_type</c>. Bad type on some arguments.
1262
<p><c>node_not_running</c>. Node not running.
1266
<p><c>truncated_binary_file</c>. Truncated binary in file.
1270
<p><c>active</c>. Some delete operations require that
1271
all active records are removed.
1275
<p><c>illegal</c>. Operation not supported on record.
1279
<p>The <c>Error</c> may be <c>Reason</c>,
1280
<c>{error, Reason}</c>, or <c>{aborted, Reason}</c>. The
1281
<c>Reason</c> may be an atom or a tuple with <c>Reason</c>
1282
as an atom in the first field.</p>
1286
<name>ets(Fun, [, Args]) -> ResultOfFun | exit(Reason)</name>
1287
<fsummary>Call the Fun in a raw context which is not protected by a transaction.</fsummary>
1289
<p>Call the <c>Fun</c> in a raw context which is not protected by
1290
a transaction. The Mnesia function call is performed in the
1291
<c>Fun</c> are performed directly on the local <c>ets</c> tables on
1292
the assumption that the local storage type is
1293
<c>ram_copies</c> and the tables are not replicated to other
1294
nodes. Subscriptions are not triggered and checkpoints are
1295
not updated, but it is extremely fast. This function can
1296
also be applied to <c>disc_copies</c> tables if all
1297
operations are read only. See <c>mnesia:activity/4</c>
1298
and the Mnesia User's Guide for more details.</p>
1299
<p><em>Note:</em> Calling (nesting) a <c>mnesia:ets</c>
1300
inside a transaction context will inherit the transaction semantics.</p>
1304
<name>first(Tab) -> Key | transaction abort </name>
1305
<fsummary>Return the key for the first record in a table.</fsummary>
1307
<p>Records in <c>set</c> or <c>bag</c> tables are not ordered.
1309
is an ordering of the records which is not known
1310
to the user. Accordingly, it is possible to traverse a table by means
1311
of this function in conjunction with the <c>mnesia:next/2</c>
1314
<p>If there are no records at all in the table, this function
1315
returns the atom <c>'$end_of_table'</c>. For this reason, it
1316
is highly undesirable, but not disallowed, to use this atom
1317
as the key for any user records.</p>
1321
<name>foldl(Function, Acc, Table) -> NewAcc | transaction abort </name>
1322
<fsummary>Call Function for each record in Table </fsummary>
1324
<p>Iterates over the table <c>Table</c> and calls
1325
<c>Function(Record, NewAcc)</c> for each <c>Record</c> in the table.
1326
The term returned from <c>Function</c> will be used as the second
1327
argument in the next call to the <c>Function</c>.
1329
<p><c>foldl</c> returns the same term as the last call to
1330
<c>Function</c> returned.</p>
1334
<name>foldr(Function, Acc, Table) -> NewAcc | transaction abort </name>
1335
<fsummary>Call Function for each record in Table </fsummary>
1337
<p>This function works exactly as
1338
<c>foldl/3</c> but iterates the table in the opposite order
1339
for the <c>ordered_set</c> table type. For
1340
all other table types, <c>foldr/3</c> and
1341
<c>foldl/3</c> are synonyms.</p>
1345
<name>force_load_table(Tab) -> yes | ErrorDescription </name>
1346
<fsummary>Force a table to be loaded into the system </fsummary>
1348
<p>The Mnesia algorithm for table load might lead to a
1349
situation where a table cannot be loaded. This situation
1350
occurs when a node is started and Mnesia concludes, or
1351
suspects, that another copy of the table was active after
1352
this local copy became inactive due to a system crash.
1354
<p>If this situation is not acceptable, this function can be
1355
used to override the strategy of the Mnesia table load
1356
algorithm. This could lead to a situation where some
1357
transaction effects are lost with a inconsistent database as
1358
result, but for some applications high availability is more
1359
important than consistent data.</p>
1363
<name>index_match_object(Pattern, Pos) -> transaction abort | ObjList</name>
1364
<fsummary>Match records and utilizes index information.</fsummary>
1366
<p>Invokes <c>mnesia:index_match_object(Tab, Pattern, Pos, read)</c> where <c>Tab</c> is <c>element(1, Pattern)</c>.</p>
1370
<name>index_match_object(Tab, Pattern, Pos, LockKind) -> transaction abort | ObjList</name>
1371
<fsummary>Match records and utilizes index information.</fsummary>
1373
<p>In a manner similar to the <c>mnesia:index_read/3</c>
1374
function, we can also utilize any index information when we
1375
try to match records. This function takes a pattern which
1376
obeys the same rules as the <c>mnesia:match_object/3</c>
1377
function with the exception that this function requires the
1378
following conditions:
1380
<list type="bulleted">
1382
<p>The table <c>Tab</c> must have an index on
1383
position <c>Pos</c>.
1387
<p>The element in position <c>Pos</c> in
1388
<c>Pattern</c> must be bound. <c>Pos</c> may either be
1389
an integer (#record.Field), or an attribute name.</p>
1392
<p>The two index search functions described here are
1393
automatically invoked when searching tables with <c>qlc</c>
1394
list comprehensions and also when using the low level
1395
<c>mnesia:[dirty_]match_object</c> functions.
1398
<p>The semantics of this function is context sensitive. See
1399
<c>mnesia:activity/4</c> for more information. In transaction
1400
context it acquires a lock of type <c>LockKind</c> on the
1401
entire table or on a single record. Currently, the lock type
1402
<c>read</c> is supported.
1407
<name>index_read(Tab, SecondaryKey, Pos) -> transaction abort | RecordList </name>
1408
<fsummary>Read records via index table. </fsummary>
1410
<p>Assume there is an index on position <c>Pos</c> for a
1411
certain record type. This function can be used to read the
1412
records without knowing the actual key for the record. For
1413
example, with an index in position 1 of the <c>person</c>
1414
table, the call <c>mnesia:index_read(person, 36, #person.age)</c> returns a list of all persons with age
1415
equal to 36. <c>Pos</c> may also be an attribute name
1416
(atom), but if the notation <c>mnesia:index_read(person, 36, age)</c> is used, the field position will be searched for in
1417
runtime, for each call.
1419
<p>The semantics of this function is context sensitive. See
1420
<c>mnesia:activity/4</c> for more information. In transaction
1421
context it acquires a read lock on the entire table.</p>
1425
<name>info() -> ok </name>
1426
<fsummary>Print some information about the system on the tty.</fsummary>
1428
<p>Prints some information about the system on the tty.
1429
This function may be used even if Mnesia is not started.
1430
However, more information will be displayed if Mnesia is
1435
<name>install_fallback(Opaque) -> ok | {error,Reason}</name>
1436
<fsummary>Install a backup as fallback.</fsummary>
1438
<p>Invokes <c>mnesia:install_fallback(Opaque, Args)</c> where
1439
<c>Args</c> is <c>[{scope, global}]</c>.</p>
1443
<name>install_fallback(Opaque), BackupMod) -> ok | {error,Reason}</name>
1444
<fsummary>Install a backup as fallback.</fsummary>
1446
<p>Invokes <c>mnesia:install_fallback(Opaque, Args)</c> where
1447
<c>Args</c> is <c>[{scope, global}, {module, BackupMod}]</c>.</p>
1451
<name>install_fallback(Opaque, Args) -> ok | {error,Reason}</name>
1452
<fsummary>Install a backup as fallback.</fsummary>
1454
<p>This function is used to install a backup as fallback. The
1455
fallback will be used to restore the database at the next
1456
start-up. Installation of fallbacks requires Erlang to be up
1457
and running on all the involved nodes, but it does not
1458
matter if Mnesia is running or not. The installation of the
1459
fallback will fail if the local node is not one of the disc
1460
resident nodes in the backup.
1462
<p><c>Args</c> is a list of the following tuples:
1464
<list type="bulleted">
1466
<p><c>{module, BackupMod}</c>.
1467
All accesses of the backup media is performed via a
1468
callback module named <c>BackupMod</c>. The
1469
<c>Opaque</c> argument is forwarded to the callback
1470
module which may interpret it as it wish. The default
1471
callback module is called <c>mnesia_backup</c> and it
1472
interprets the <c>Opaque</c> argument as a local
1473
filename. The default for this module is also
1474
configurable via the <c>-mnesia mnesia_backup</c>
1475
configuration parameter. </p>
1478
<p><c>{scope, Scope}</c>
1479
The <c>Scope</c> of a fallback may either be
1480
<c>global</c> for the entire database or <c>local</c>
1481
for one node. By default, the installation of a fallback
1482
is a global operation which either is performed all
1483
nodes with disc resident schema or none. Which nodes
1484
that are disc resident or not, is determined from the
1485
schema info in the backup.</p>
1486
<p>If the <c>Scope</c> of the operation is <c>local</c>
1487
the fallback will only be installed on the local node.</p>
1490
<p><c>{mnesia_dir, AlternateDir}</c>
1491
This argument is only valid if the scope of the
1492
installation is <c>local</c>. Normally the installation
1493
of a fallback is targeted towards the Mnesia directory
1494
as configured with the <c>-mnesia dir</c> configuration
1495
parameter. But by explicitly supplying an
1496
<c>AlternateDir</c> the fallback will be installed there
1497
regardless of the Mnesia directory configuration
1498
parameter setting. After installation of a fallback on
1499
an alternate Mnesia directory that directory is fully
1500
prepared for usage as an active Mnesia directory.
1502
<p>This is a somewhat dangerous feature which must be
1503
used with care. By unintentional mixing of directories
1504
you may easily end up with a inconsistent database, if
1505
the same backup is installed on more than one directory.</p>
1511
<name>is_transaction() -> boolean </name>
1512
<fsummary>Check if code is running in a transaction.</fsummary>
1514
<p>When this function is executed inside a transaction context
1515
it returns <c>true</c>, otherwise <c>false</c>.</p>
1519
<name>last(Tab) -> Key | transaction abort </name>
1520
<fsummary>Return the key for the last record in a table.</fsummary>
1522
<p>This function works exactly
1523
<c>mnesia:first/1</c> but returns the last object in
1524
Erlang term order for the <c>ordered_set</c> table type. For
1525
all other table types, <c>mnesia:first/1</c> and
1526
<c>mnesia:last/1</c> are synonyms.</p>
1530
<name>load_textfile(Filename)</name>
1531
<fsummary>Load tables from a text file.</fsummary>
1533
<p>Loads a series of definitions and data found in the
1534
text file (generated with <c>mnesia:dump_to_textfile/1</c>)
1535
into Mnesia. This function also starts Mnesia and possibly
1536
creates a new schema. This function is intended for
1537
educational purposes only and using other functions to deal
1538
with real backups, is recommended.</p>
1542
<name>lock(LockItem, LockKind) -> Nodes | ok | transaction abort</name>
1543
<fsummary>Explicit grab lock.</fsummary>
1545
<p>Write locks are normally acquired on all nodes where a
1546
replica of the table resides (and is active). Read locks are
1547
acquired on one node (the local node if a local
1548
replica exists). Most of the context sensitive access functions
1549
acquire an implicit lock if they are invoked in a
1550
transaction context. The granularity of a lock may either
1551
be a single record or an entire table.
1553
<p>The normal usage is to call the function without checking
1554
the return value since it exits if it fails and the
1555
transaction is restarted by the transaction manager. It
1556
returns all the locked nodes if a write lock is aquired, and
1557
<c>ok</c> if it was a read lock.
1559
<p>This function <c>mnesia:lock/2</c> is intended to support
1560
explicit locking on tables but also intended for situations
1561
when locks need to be acquired regardless of how tables are
1562
replicated. Currently, two <c>LockKind</c>'s are supported:
1565
<tag><c>write</c></tag>
1567
<p>Write locks are exclusive, which means that if one
1568
transaction manages to acquire a write lock on an item,
1569
no other transaction may acquire any kind of lock on the
1573
<tag><c>read</c></tag>
1575
<p>Read locks may be shared, which means that if one
1576
transaction manages to acquire a read lock on an item,
1577
other transactions may also acquire a read lock on the
1578
same item. However, if someone has a read lock no one can
1579
acquire a write lock at the same item. If some one has a
1580
write lock no one can acquire a read lock nor
1581
a write lock at the same item.</p>
1584
<p>Conflicting lock requests are automatically queued if there
1585
is no risk of a deadlock. Otherwise the transaction must be
1586
aborted and executed again. Mnesia does this automatically
1587
as long as the upper limit of maximum <c>retries</c> is not
1588
reached. See <c>mnesia:transaction/3</c> for the details.
1590
<p>For the sake of completeness sticky write locks will also
1591
be described here even if a sticky write lock is not
1592
supported by this particular function:
1595
<tag><c>sticky_write</c></tag>
1597
<p>Sticky write locks are a mechanism which can be used
1598
to optimize write lock acquisition. If your application
1599
uses replicated tables mainly for fault tolerance (as
1600
opposed to read access optimization purpose), sticky
1601
locks may be the best option available.
1603
<p>When a sticky write lock is acquired, all nodes will be
1604
informed which node is locked. Subsequently,
1605
sticky lock requests from the same node will be
1606
performed as a local operation without any
1607
communication with other nodes. The sticky lock
1608
lingers on the node even after the transaction has
1609
ended. See the Mnesia User's Guide for more information.</p>
1612
<p>Currently, two kinds of <c>LockItem</c>'s are supported by
1616
<tag><c>{table, Tab}</c></tag>
1618
<p>This acquires a lock of type <c>LockKind</c> on the
1619
entire table <c>Tab</c>.
1622
<tag><c>{global, GlobalKey, Nodes}</c></tag>
1624
<p>This acquires a lock of type <c>LockKind</c> on the
1625
global resource <c>GlobalKey</c>. The lock is acquired
1626
on all active nodes in the <c>Nodes</c> list. </p>
1629
<p>Locks are released when the outermost transaction ends.
1631
<p>The semantics of this function is context sensitive. See
1632
<c>mnesia:activity/4</c> for more information. In transaction
1633
context it acquires locks otherwise it just ignores the
1638
<name>match_object(Pattern) ->transaction abort | RecList </name>
1639
<fsummary>Match <c>Pattern</c>for records. </fsummary>
1641
<p>Invokes <c>mnesia:match_object(Tab, Pattern, read)</c> where
1642
<c>Tab</c> is <c>element(1, Pattern)</c>.</p>
1646
<name>match_object(Tab, Pattern, LockKind) ->transaction abort | RecList </name>
1647
<fsummary>Match <c>Pattern</c>for records. </fsummary>
1649
<p>This function takes a pattern with 'don't care' variables
1650
denoted as a '_' parameter. This function returns a list of
1651
records which matched the pattern. Since the second element
1652
of a record in a table is considered to be the key for the
1653
record, the performance of this function depends on whether
1654
this key is bound or not.
1656
<p>For example, the call <c>mnesia:match_object(person, {person, '_', 36, '_', '_'}, read)</c> returns a list of all person records with an
1657
age field of thirty-six (36).
1659
<p>The function <c>mnesia:match_object/3</c>
1660
automatically uses indices if these exist. However, no
1661
heuristics are performed in order to select the best
1664
<p>The semantics of this function is context sensitive. See
1665
<c>mnesia:activity/4</c> for more information. In transaction
1666
context it acquires a lock of type <c>LockKind</c> on the
1667
entire table or a single record. Currently, the lock type
1668
<c>read</c> is supported.</p>
1672
<name>move_table_copy(Tab, From, To) -> {aborted, Reason} | {atomic, ok}</name>
1673
<fsummary>Move the copy of table <c>Tab</c>from node<c>From</c>to node <c>To</c>.</fsummary>
1675
<p>Moves the copy of table <c>Tab</c> from node
1676
<c>From</c> to node <c>To</c>.
1678
<p>The storage type is preserved. For example, a RAM table
1679
moved from one node remains a RAM on the new node. It is
1680
still possible for other transactions to read and write in
1681
the table while it is being moved.
1683
<p>This function cannot be used on <c>local_content</c> tables.</p>
1687
<name>next(Tab, Key) -> Key | transaction abort </name>
1688
<fsummary>Return the next key in a table. </fsummary>
1690
<p>This function makes it possible to traverse a table
1691
and perform operations on all records in the table. When
1692
the end of the table is reached, the special key
1693
<c>'$end_of_table'</c> is returned. Otherwise, the function
1694
returns a key which can be used to read the actual record.</p>
1698
<name>prev(Tab, Key) -> Key | transaction abort </name>
1699
<fsummary>Return the previous key in a table. </fsummary>
1701
<p>This function works exactly
1702
<c>mnesia:next/2</c> but returns the previous object in
1703
Erlang term order for the ordered_set table type. For
1704
all other table types, <c>mnesia:next/2</c> and
1705
<c>mnesia:prev/2</c> are synonyms.\011 </p>
1709
<name>read({Tab, Key}) -> transaction abort | RecordList </name>
1710
<fsummary>Read records(s) with a given key. </fsummary>
1712
<p>Invokes <c>mnesia:read(Tab, Key, read)</c>.</p>
1716
<name>read(Tab, Key) -> transaction abort | RecordList </name>
1717
<fsummary>Read records(s) with a given key. </fsummary>
1719
<p>Invokes <c>mnesia:read(Tab, Key, read)</c>.</p>
1723
<name>read(Tab, Key, LockKind) -> transaction abort | RecordList </name>
1724
<fsummary>Read records(s) with a given key. </fsummary>
1726
<p>This function reads all records from table <c>Tab</c> with
1727
key <c>Key</c>. This function has the same semantics
1728
regardless of the location of <c>Tab</c>. If the table is
1729
of type <c>bag</c>, the <c>mnesia:read(Tab, Key)</c> can
1730
return an arbitrarily long list. If the table is of type
1731
<c>set</c>, the list is either of length 1, or <c>[]</c>.
1733
<p>The semantics of this function is context sensitive. See
1734
<c>mnesia:activity/4</c> for more information. In transaction
1735
context it acquires a lock of type
1736
<c>LockKind</c>. Currently, the lock types <c>read</c>,
1737
<c>write</c> and <c>sticky_write</c> are supported.
1739
<p>If the user wants to update the record it is more efficient to
1740
use <c>write/sticky_write</c> as the LockKind.
1745
<name>read_lock_table(Tab) -> ok | transaction abort</name>
1746
<fsummary>Set a read lock on an entire table.</fsummary>
1748
<p>Invokes <c>mnesia:lock({table, Tab}, read)</c>.</p>
1752
<name>report_event(Event) -> ok</name>
1753
<fsummary>Report a user event to Mnesia's event handler.</fsummary>
1755
<p>When tracing a system of Mnesia applications it is useful
1756
to be able to interleave Mnesia's own events with
1757
application related events that give information about the
1758
application context.
1760
<p>Whenever the application begins a
1761
new and demanding Mnesia task, or if it is entering a new
1762
interesting phase in its execution, it may be a good idea to
1763
use <c>mnesia:report_event/1</c>. The <c>Event</c> may be
1764
any term and generates a <c>{mnesia_user, Event}</c> event
1765
for any processes that subscribe to Mnesia system
1770
<name>restore(Opaque, Args) -> {atomic, RestoredTabs} |{aborted, Reason}</name>
1771
<fsummary>Online restore of backup.</fsummary>
1773
<p>With this function, tables may be restored online from a
1774
backup without restarting Mnesia. <c>Opaque</c> is forwarded
1775
to the backup module. <c>Args</c> is a list of the following
1778
<list type="bulleted">
1780
<p><c>{module,BackupMod}</c> The backup module
1781
<c>BackupMod</c> will be used to access the backup
1782
media. If omitted, the default backup module will be
1786
<item><c>{skip_tables, TabList}</c> Where <c>TabList</c>
1787
is a list of tables which should not be read from the
1790
<item><c>{clear_tables, TabList}</c> Where
1791
<c>TabList</c> is a list of tables which should be
1792
cleared, before the records from the backup are inserted,
1793
ie. all records in the tables are deleted before the
1794
tables are restored. Schema information about the tables
1795
is not cleared or read from backup.
1797
<item><c>{keep_tables, TabList}</c> Where <c>TabList</c>
1798
is a list of tables which should be not be cleared, before
1799
the records from the backup are inserted, i.e. the records
1800
in the backup will be added to the records in the table.
1801
Schema information about the tables is not cleared or read
1804
<item><c>{recreate_tables, TabList}</c> Where
1805
<c>TabList</c> is a list of tables which should be
1806
re-created, before the records from the backup are
1807
inserted. The tables are first deleted and then created with
1808
the schema information from the backup. All the nodes in the
1809
backup needs to be up and running.
1811
<item><c>{default_op, Operation}</c> Where <c>Operation</c> is
1812
one of the following operations <c>skip_tables</c>,
1813
<c>clear_tables</c>, <c>keep_tables</c> or
1814
<c>recreate_tables</c>. The default operation specifies
1815
which operation should be used on tables from the backup
1816
which are not specified in any of the lists above. If
1817
omitted, the operation <c>clear_tables</c> will be used.
1820
<p>The affected tables are write locked during the
1821
restoration, but regardless of the lock conflicts caused by
1822
this, the applications can continue to do their work while
1823
the restoration is being performed. The restoration is
1824
performed as one single transaction.
1826
<p>If the database is
1827
huge, it may not be possible to restore it online. In such
1828
cases, the old database must be restored by installing a
1829
fallback and then restart.</p>
1833
<name>s_delete({Tab, Key}) -> ok | transaction abort </name>
1834
<fsummary>Set sticky lock and delete records.</fsummary>
1836
<p>Invokes <c>mnesia:delete(Tab, Key, sticky_write)</c></p>
1840
<name>s_delete_object(Record) -> ok | transaction abort </name>
1841
<fsummary>Set sticky lock and delete record.</fsummary>
1843
<p>Invokes <c>mnesia:delete_object(Tab, Record, sticky_write)</c> where <c>Tab</c> is <c>element(1, Record)</c>.</p>
1847
<name>s_write(Record) -> ok | transaction abort </name>
1848
<fsummary>Write <c>Record</c>and sets stick lock.</fsummary>
1850
<p>Invokes <c>mnesia:write(Tab, Record, sticky_write)</c>
1851
where <c>Tab</c> is <c>element(1, Record)</c>.</p>
1855
<name>schema() -> ok </name>
1856
<fsummary>Print information about all table definitions on the tty. </fsummary>
1858
<p>Prints information about all table definitions on the tty.</p>
1862
<name>schema(Tab) -> ok </name>
1863
<fsummary>Print information about one table definition on the tty.</fsummary>
1865
<p>Prints information about one table definition on the tty.</p>
1869
<name>select(Tab, MatchSpec [, Lock]) -> transaction abort | [Object] </name>
1870
<fsummary>Match the objects in <c>Tab</c>against <c>MatchSpec</c>.</fsummary>
1872
<p>Matches the objects in the table <c>Tab</c> using a
1873
match_spec as described in the ERTS Users Guide. Optionally a lock
1874
<c>read</c> or <c>write</c> can be given as the third
1875
argument, default is <c>read</c>. The return value depends
1876
on the <c>MatchSpec</c>.</p>
1877
<p><em>Note:</em> for best performance <c>select</c> should
1878
be used before any modifying operations are done on that table
1879
in the same transaction, i.e. don't use <c>write</c> or <c>delete</c>
1880
before a <c>select</c>.</p>
1881
<p>In its simplest forms the match_spec's look like this:</p>
1882
<list type="bulleted">
1883
<item>MatchSpec = [MatchFunction]</item>
1884
<item>MatchFunction = {MatchHead, [Guard], [Result]}</item>
1885
<item>MatchHead = tuple() | record()</item>
1886
<item>Guard = {"Guardtest name", ...}</item>
1887
<item>Result = "Term construct"</item>
1889
<p>See the ERTS Users Guide and <c>ets</c> documentation for a
1890
complete description of the select.</p>
1891
<p>For example to find the names of all male persons with an age over 30 in table
1894
\011 MatchHead = #person{name='$1', sex=male, age='$2', _='_'},
1895
\011 Guard = {'>', '$2', 30},
1897
\011 mnesia:select(Tab,[{MatchHead, [Guard], [Result]}]),
1902
<name>select(Tab, MatchSpec, NObjects, Lock) -> transaction abort | {[Object],Cont} | '$end_of_table'</name>
1903
<fsummary>Match the objects in <c>Tab</c>against <c>MatchSpec</c>.</fsummary>
1905
<p>Matches the objects in the table <c>Tab</c> using a
1906
match_spec as described in ERTS users guide, and returns
1907
a chunk of terms and a continuation, the wanted number
1908
of returned terms is specified by the <c>NObjects</c> argument.
1909
The lock argument can be <c>read</c> or <c>write</c>.
1910
The continuation should be used as argument to <c>mnesia:select/1</c>,
1911
if more or all answers are needed.</p>
1912
<p><em>Note:</em> for best performance <c>select</c> should
1913
be used before any modifying operations are done on that
1914
table in the same transaction, i.e. don't use
1915
<c>mnesia:write</c> or <c>mnesia:delete</c> before a
1916
<c>mnesia:select</c>. For efficiency the <c>NObjects</c> is
1917
a recommendation only and the result may contain anything
1918
from an empty list to all available results. </p>
1922
<name>select(Cont) -> transaction abort | {[Object],Cont} | '$end_of_table'</name>
1923
<fsummary>Continues selecting objects. </fsummary>
1925
<p>Selects more objects with the match specification initiated
1926
by <c>mnesia:select/4</c>.
1928
<p><em>Note:</em> Any modifying operations, i.e. <c>mnesia:write</c>
1929
or <c>mnesia:delete</c>, that are done between the <c>mnesia:select/4</c>
1930
and <c>mnesia:select/1</c> calls will not be visible in the result.</p>
1934
<name>set_debug_level(Level) -> OldLevel</name>
1935
<fsummary>Change the internal debug level of Mnesia</fsummary>
1937
<p>Changes the internal debug level of Mnesia. See the
1938
chapter about configuration parameters for details.</p>
1942
<name>set_master_nodes(MasterNodes) -> ok | {error, Reason} </name>
1943
<fsummary>Set the master nodes for all tables</fsummary>
1945
<p>For each table Mnesia will determine its replica nodes
1946
(<c>TabNodes</c>) and invoke <c>mnesia:set_master_nodes(Tab, TabMasterNodes)</c> where <c>TabMasterNodes</c> is the
1947
intersection of <c>MasterNodes</c> and <c>TabNodes</c>. See
1948
<c>mnesia:set_master_nodes/2</c> about the semantics.</p>
1952
<name>set_master_nodes(Tab, MasterNodes) -> ok | {error, Reason} </name>
1953
<fsummary>Set the master nodes for a table</fsummary>
1955
<p>If the application detects that there has been a
1956
communication failure (in a potentially partitioned network) which
1957
may have caused an inconsistent database, it may use the
1958
function <c>mnesia:set_master_nodes(Tab, MasterNodes)</c> to
1959
define from which nodes each table will be loaded.
1960
At startup Mnesia's normal table load algorithm will be
1961
bypassed and the table will be loaded from one of the master
1962
nodes defined for the table, regardless of when and if Mnesia
1963
was terminated on other nodes. The <c>MasterNodes</c> may only
1964
contain nodes where the table has a replica and if the
1965
<c>MasterNodes</c> list is empty, the master node recovery
1966
mechanism for the particular table will be reset and the
1967
normal load mechanism will be used at next restart.
1969
<p>The master node setting is always local and it may be
1970
changed regardless of whether Mnesia is started or not.
1972
<p>The database may also become inconsistent if the
1973
<c>max_wait_for_decision</c> configuration parameter is used
1974
or if <c>mnesia:force_load_table/1</c> is used.</p>
1978
<name>snmp_close_table(Tab) -> {aborted, R} | {atomic, ok}</name>
1979
<fsummary>Remove the possibility for SNMP to manipulate the table.</fsummary>
1981
<p>Removes the possibility for SNMP to manipulate the
1986
<name>snmp_get_mnesia_key(Tab, RowIndex) -> {ok, Key} | undefined</name>
1987
<fsummary>Get the corresponding Mnesia key from an SNMP index.</fsummary>
1989
<v>Tab ::= atom()</v>
1990
<v>RowIndex ::= [integer()]</v>
1991
<v>Key ::= key() | {key(), key(), ...}</v>
1992
<v>key() ::= integer() | string() | [integer()]</v>
1995
<p>Transforms an SNMP index to the corresponding Mnesia key.
1996
If the SNMP table has multiple keys, the key is a tuple of
1997
the key columns.</p>
2001
<name>snmp_get_next_index(Tab, RowIndex) -> {ok, NextIndex} | endOfTable</name>
2002
<fsummary>Get the index of the next lexicographical row.</fsummary>
2004
<v>Tab ::= atom()</v>
2005
<v>RowIndex ::= [integer()]</v>
2006
<v>NextIndex ::= [integer()]</v>
2009
<p>The <c>RowIndex</c> may specify a non-existing row.
2010
Specifically, it might be the empty list. Returns the index
2011
of the next lexicographical row. If <c>RowIndex</c> is the
2012
empty list, this function will return the index of the first row
2017
<name>snmp_get_row(Tab, RowIndex) -> {ok, Row} | undefined</name>
2018
<fsummary>Retrieve a row indexed by an SNMP index.</fsummary>
2020
<v>Tab ::= atom()</v>
2021
<v>RowIndex ::= [integer()]</v>
2022
<v>Row ::= record(Tab)</v>
2025
<p>Makes it possible to read a row by its SNMP index. This
2026
index is specified as an SNMP OBJECT IDENTIFIER, a list of
2031
<name>snmp_open_table(Tab, SnmpStruct) -> {aborted, R} | {atomic, ok}</name>
2032
<fsummary>Organize a Mnesia table as an SNMP table.</fsummary>
2034
<v>Tab ::= atom()</v>
2035
<v>SnmpStruct ::= [{key, type()}]</v>
2036
<v>type() ::= type_spec() | {type_spec(), type_spec(), ...}</v>
2037
<v>type_spec() ::= fix_string | string | integer</v>
2040
<p>It is possible to establish a direct one to one mapping
2041
between Mnesia tables and SNMP tables. Many
2042
telecommunication applications are controlled and monitored
2043
by the SNMP protocol. This connection between Mnesia and
2044
SNMP makes it simple and convenient to achieve this.
2046
<p>The <c>SnmpStruct</c> argument is a list of SNMP
2047
information. Currently, the only information needed is
2048
information about the key types in the table. It is not
2049
possible to handle multiple keys in Mnesia, but many SNMP
2050
tables have multiple keys. Therefore, the following
2051
convention is used: if a table has multiple keys, these must
2052
always be stored as a tuple of the keys. Information about
2053
the key types is specified as a tuple of atoms describing
2054
the types. The only significant type is
2055
<c>fix_string</c>. This means that a string has fixed
2059
mnesia:snmp_open_table(person, [{key, string}])
2061
<p>causes the <c>person</c> table to be ordered as an SNMP
2064
<p>Consider the following schema for a table of company
2065
employees. Each employee is identified by department number
2066
and name. The other table column stores the telephone number:
2069
mnesia:create_table(employee,
2070
[{snmp, [{key, {integer, string}}]},
2071
{attributes, record_info(fields, employees)}]),
2073
<p>The corresponding SNMP table would have three columns;
2074
<c>department</c>, <c>name</c> and <c>telno</c>.
2076
<p>It is possible to have table columns that are not visible
2077
through the SNMP protocol. These columns must be the last
2078
columns of the table. In the previous example, the SNMP
2079
table could have columns <c>department</c> and <c>name</c>
2080
only. The application could then use the <c>telno</c> column
2081
internally, but it would not be visible to the SNMP
2084
<p>In a table monitored by SNMP, all elements must be
2085
integers, strings, or lists of integers.
2087
<p>When a table is SNMP ordered, modifications are more
2088
expensive than usual, O(logN). And more memory is used.
2090
<p><em>Note:</em>Only the lexicographical SNMP ordering is
2091
implemented in Mnesia, not the actual SNMP monitoring.</p>
2095
<name>start() -> ok | {error, Reason} </name>
2096
<fsummary>Start a local Mnesia system.</fsummary>
2098
<p>The start-up procedure for a set of Mnesia nodes is a
2099
fairly complicated operation. A Mnesia system consists of a set
2100
of nodes, with Mnesia started locally on all
2101
participating nodes. Normally, each node has a directory where
2102
all the Mnesia files are written. This directory will be
2103
referred to as the Mnesia directory. Mnesia may also be
2104
started on disc-less nodes. See <c>mnesia:create_schema/1</c>
2105
and the Mnesia User's Guide for more information about disc-less
2108
<p>The set of nodes which makes up a Mnesia system is kept in
2109
a schema and it is possible to add and remove Mnesia nodes
2110
from the schema. The initial schema is normally created on
2111
disc with the function <c>mnesia:create_schema/1</c>. On
2112
disc-less nodes, a tiny default schema is generated each time
2113
Mnesia is started. During the start-up procedure, Mnesia
2114
will exchange schema information between the nodes in order
2115
to verify that the table definitions are compatible.
2117
<p>Each schema has a unique cookie which may be regarded as a
2118
unique schema identifier. The cookie must be the same on all
2119
nodes where Mnesia is supposed to run. See the Mnesia
2120
User's Guide for more information about these details.
2122
<p>The schema file, as well as all other files which Mnesia
2123
needs, are kept in the Mnesia directory. The command line
2124
option <c>-mnesia dir Dir</c> can be used to specify the
2125
location of this directory to the Mnesia system. If no such
2126
command line option is found, the name of the directory
2127
defaults to <c>Mnesia.Node</c>.
2129
<p><c>application:start(mnesia)</c> may also be used.</p>
2133
<name>stop() -> stopped </name>
2134
<fsummary>Stop Mnesia locally.</fsummary>
2136
<p>Stops Mnesia locally on the current node.
2138
<p><c>application:stop(mnesia)</c> may also be used.</p>
2142
<name>subscribe(EventCategory)</name>
2143
<fsummary>Subscribe to events of type <c>EventCategory</c>.</fsummary>
2145
<p>Ensures that a copy of all events of type
2146
<c>EventCategory</c> are sent to the caller. The event
2147
types available are described in the Mnesia User's Guide.</p>
2151
<name>sync_dirty(Fun, [, Args]) -> ResultOfFun | exit(Reason) </name>
2152
<fsummary>Call the Fun in a context which is not protected by a transaction.</fsummary>
2154
<p>Call the <c>Fun</c> in a context which is not protected
2155
by a transaction. The Mnesia function calls performed in the
2156
<c>Fun</c> are mapped to the corresponding dirty functions.
2157
It is performed in almost the same context as
2158
<c>mnesia:async_dirty/1,2</c>. The difference is that the
2159
operations are performed synchronously. The caller waits for
2160
the updates to be performed on all active replicas before
2161
the <c>Fun</c> returns. See <c>mnesia:activity/4</c> and the
2162
Mnesia User's Guide for more details.</p>
2166
<name>sync_transaction(Fun, [[, Args], Retries]) -> {aborted, Reason} | {atomic, ResultOfFun} </name>
2167
<fsummary>Synchronously execute a transaction.</fsummary>
2169
<p>This function waits until data have been committed and
2170
logged to disk (if disk is used) on every involved node before
2171
it returns, otherwise it behaves as
2172
<c>mnesia:transaction/[1,2,3]</c>.</p>
2173
<p>This functionality can be used to avoid that one process may overload
2174
a database on another node.</p>
2178
<name>system_info(InfoKey) -> Info | exit({aborted, Reason})</name>
2179
<fsummary>Return information about the Mnesia system</fsummary>
2181
<p>Returns information about the Mnesia system, such as
2182
transaction statistics, db_nodes, and configuration parameters.
2184
<list type="bulleted">
2186
<p><c>all</c>. This argument returns a list of all
2187
local system information. Each element is a
2188
<c>{InfoKey, InfoVal}</c> tuples.<em>Note:</em> New <c>InfoKey</c>'s may
2189
be added and old undocumented <c>InfoKey</c>'s may be removed without
2193
<p><c>access_module</c>. This argument returns the name of
2194
the module which is configured to be the activity access
2199
<p><c>auto_repair</c>. This argument returns
2200
<c>true</c> or <c>false</c> to indicate if Mnesia is
2201
configured to invoke the auto repair facility on corrupted
2206
<p><c>backup_module</c>. This argument returns the name of
2207
the module which is configured to be the backup
2212
<p><c>checkpoints</c>. This argument
2213
returns a list of the names of the
2214
checkpoints currently active on this node.
2218
<p><c>event_module</c>. This argument returns the name of
2219
the module which is the event handler callback module.
2223
<p><c>db_nodes</c>. This argument returns
2224
the nodes which make up the persistent database. Disc
2225
less nodes will only be included in the list of nodes if
2226
they explicitly has been added to the schema, e.g. with
2227
<c>mnesia:add_table_copy/3</c>. The function can be
2228
invoked even if Mnesia is not yet running.
2232
<p><c>debug</c>. This argument returns the current
2233
debug level of Mnesia.
2237
<p><c>directory</c>. This argument returns the name of
2238
the Mnesia directory. It can be invoked even if Mnesia is
2243
<p><c>dump_log_load_regulation</c>. This argument
2244
returns a boolean which tells whether Mnesia is
2245
configured to load regulate the dumper process or not.
2246
This feature is temporary and will disappear in future
2251
<p><c>dump_log_time_threshold</c>. This argument
2252
returns the time threshold for transaction log dumps in
2257
<p><c>dump_log_update_in_place</c>. This argument
2258
returns a boolean which tells whether Mnesia is
2259
configured to perform the updates in the dets files
2260
directly or if the updates should be performed in a copy
2265
<p><c>dump_log_write_threshold</c>. This argument
2266
returns the write threshold for transaction log dumps as
2267
the number of writes to the transaction log.
2271
<p><c>extra_db_nodes</c>. This argument returns a list
2272
of extra db_nodes to be contacted at start-up.
2276
<p><c>fallback_activated</c>. This argument returns
2277
true if a fallback is activated, otherwise false.
2281
<p><c>held_locks</c>. This argument returns a list of
2282
all locks held by the local Mnesia lock manager.
2286
<p><c>is_running</c>. This argument returns <c>yes</c>
2287
or <c>no</c> to indicate if Mnesia is running. It may
2288
also return <c>starting</c> or <c>stopping</c>. Can be
2289
invoked even if Mnesia is not yet running.
2293
<p><c>local_tables</c>. This argument returns a list
2294
of all tables which are configured to reside locally.
2298
<p><c>lock_queue</c>. This argument returns a list of
2299
all transactions that are queued for execution by the
2304
<p><c>log_version</c>. This argument returns the
2305
version number of the Mnesia transaction log format.
2309
<p><c>master_node_tables</c>. This argument returns a
2310
list of all tables with at least one master node.
2314
<p><c>protocol_version</c>. This argument
2315
returns the version number
2316
of the Mnesia inter-process communication protocol.
2320
<p><c>running_db_nodes</c>. This argument returns a
2321
list of nodes where Mnesia currently is running. This
2322
function can be invoked even if Mnesia is not yet
2323
running, but it will then have slightly different
2324
semantics. If Mnesia is down on the local node, the
2325
function will return those other <c>db_nodes</c> and
2326
<c>extra_db_nodes</c> that for the moment are up and
2327
running. If Mnesia is started, the function will return
2328
those nodes that Mnesia on the local node is fully
2329
connected to. Only those nodes that Mnesia has exchanged
2330
schema information with are included as
2331
<c>running_db_nodes</c>. After the merge of schemas, the
2332
local Mnesia system is fully operable and applications
2333
may perform access of remote replicas. Before the schema
2334
merge Mnesia will only operate locally. Sometimes there
2335
may be more nodes included in the
2336
<c>running_db_nodes</c> list than all <c>db_nodes</c>
2337
and <c>extra_db_nodes</c> together.
2341
<p><c>schema_location</c>. This argument returns the
2342
initial schema location.
2346
<p><c>subscribers</c>. This argument returns a list of
2347
local processes currently subscribing to system events.
2351
<p><c>tables</c>. This argument returns a list of all
2352
locally known tables.
2356
<p><c>transactions</c>. This argument returns a list
2357
of all currently active local transactions.
2361
<p><c>transaction_failures</c>. This argument returns
2362
a number which indicates how many transactions have
2363
failed since Mnesia was started.
2367
<p><c>transaction_commits</c>. This argument returns a
2368
number which indicates how many transactions have
2369
terminated successfully since Mnesia was started.
2373
<p><c>transaction_restarts</c>. This argument returns
2374
a number which indicates how many transactions have been
2375
restarted since Mnesia was started.
2379
<p><c>transaction_log_writes</c>. This argument
2380
returns a number which indicates the number of write
2381
operation that have been performed to the transaction
2386
<p><c>use_dir</c>. This argument returns a boolean
2387
which indicates whether the Mnesia directory is used or
2388
not. Can be invoked even if Mnesia is not yet running.
2392
<p><c>version</c>. This argument returns the current
2393
version number of Mnesia.
2400
<name>table(Tab [,[Option]]) -> QueryHandle </name>
2401
<fsummary>Return a QLC query handle.</fsummary>
2403
<p> <marker id="qlc_table"></marker>
2404
Returns a QLC (Query List Comprehension) query handle, see
2405
<seealso marker="stdlib:qlc">qlc(3)</seealso>.The module <c>qlc</c> implements a query language, it
2406
can use mnesia tables as sources of data. Calling
2407
<c>mnesia:table/1,2</c> is the means to make the <c>mnesia</c>
2408
table <c>Tab</c> usable to QLC.</p>
2409
<p>The list of Options may contain mnesia options or QLC
2410
options, the following options are recognized by Mnesia:
2411
<c>{traverse, SelectMethod},{lock, Lock},{n_objects,Number}</c>, any other option is forwarded
2412
to QLC. The <c>lock</c> option may be <c>read</c> or
2413
<c>write</c>, default is <c>read</c>. The option
2414
<c>n_objects</c> specifies (roughly) the number of objects
2415
returned from mnesia to QLC. Queries to remote tables may
2416
need a larger chunks to reduce network overhead, default
2417
<c>100</c> objects at a time are returned. The option
2418
<c>traverse</c> determines the method to traverse the whole
2419
table (if needed), the default method is <c>select</c>:</p>
2420
<list type="bulleted">
2422
<p><c>select</c>. The table is traversed by calling
2423
<c>mnesia:select/4</c> and <c>mnesia:select/1</c>. The
2424
match specification (the second argument of <c>select/3</c>)
2425
is assembled by QLC: simple filters are
2426
translated into equivalent match specifications while
2427
more complicated filters have to be applied to all
2428
objects returned by <c>select/3</c> given a match
2429
specification that matches all objects.</p>
2432
<p><c>{select, MatchSpec}</c>. As for <c>select</c>
2433
the table is traversed by calling <c>mnesia:select/3</c> and
2434
<c>mnesia:select/1</c>. The difference is that the match
2435
specification is explicitly given. This is how to state
2436
match specifications that cannot easily be expressed
2437
within the syntax provided by QLC.</p>
2443
<name>table_info(Tab, InfoKey) -> Info | exit({aborted, Reason})</name>
2444
<fsummary>Return local information about table.</fsummary>
2446
<p>The <c>table_info/2</c> function takes two arguments.
2447
The first is the name of a Mnesia table, the second is one of
2450
<list type="bulleted">
2452
<p><c>all</c>. This argument returns a list of all
2453
local table information. Each element is a <c>{InfoKey, ItemVal}</c> tuples. <em>Note:</em> New <c>InfoItem</c>'s may be
2454
added and old undocumented <c>InfoItem</c>'s may be removed without
2458
<p><c>access_mode</c>. This argument returns the
2459
access mode of the table. The access mode may either be
2460
read_only or read_write.
2464
<p><c>arity</c>. This argument returns the arity of
2465
records in the table as specified in the schema.
2469
<p><c>attributes</c>. This argument returns the table
2470
attribute names which are specified in the schema.
2474
<p><c>checkpoints</c>. This argument returns the names
2475
of the currently active checkpoints which involves this
2480
<p><c>cookie</c>. This argument returns a table cookie
2481
which is a unique system generated identifier for the
2482
table. The cookie is used internally to ensure that two
2483
different table definitions using the same table name
2484
cannot accidentally be intermixed. The cookie is
2485
generated when the table is initially created.
2489
<p><c>disc_copies</c>. This argument returns the nodes
2490
where a disc_copy of the table resides according to the
2495
<p><c>disc_only_copies </c>. This argument returns the
2496
nodes where a disc_only_copy of the table resides
2497
according to the schema.
2501
<p><c>index</c>. This argument returns the list of
2502
index position integers for the table.
2506
<p><c>load_node</c>. This argument returns the name of
2507
the node that Mnesia loaded the table from. The
2508
structure of the returned value is unspecified but may
2509
be useful for debugging purposes.
2513
<p><c>load_order</c>. This argument returns the load
2514
order priority of the table. It is an integer and
2515
defaults to <c>0</c> (zero).
2519
<p><c>load_reason</c>. This argument returns the
2520
reason of why Mnesia decided to load the table. The
2521
structure of the returned value is unspecified but may
2522
be useful for debugging purposes.
2526
<p><c>local_content</c>. This argument returns
2527
<c>true</c> or <c>false</c> to indicate whether the
2528
table is configured to have locally unique content on
2533
<p><c>master_nodes</c>. This argument returns the
2534
master nodes of a table.
2538
<p><c>memory</c>. This argument returns the number of
2539
words allocated to the table on this node.
2543
<p><c>ram_copies</c>. This argument returns the nodes
2544
where a ram_copy of the table resides according to the
2549
<p><c>record_name</c>. This argument returns the
2550
record name, common for all records in the table
2554
<p><c>size</c>. This argument returns the number of
2555
records inserted in the table.
2559
<p><c>snmp</c>. This argument returns the SNMP struct.
2560
<c>[]</c>meaning that the table currently has no SNMP
2565
<p><c>storage_type</c>.This argument returns the local
2566
storage type of the table. It can be <c>disc_copies</c>,
2567
<c>ram_copies</c>, <c>disc_only_copies</c>, or the atom
2568
<c>unknown</c>. <c>unknown</c> is returned for all
2569
tables which only reside remotely.
2573
<p><c>subscribers</c>. This argument returns a list
2574
of local processes currently subscribing to local table
2575
events which involve this table on this node.
2579
<p><c>type</c>. This argument returns the table type,
2580
which is either <c>bag</c>, <c>set</c> or <c>ordered_set</c>..
2584
<p><c>user_properties</c>. This argument returns the
2585
user associated table properties of the table. It is a
2586
list of the stored property records.
2590
<p><c>version</c>. This argument returns the current
2591
version of the table definition. The table version is
2592
incremented when the table definition is changed. The
2593
table definition may be incremented directly when the
2594
table definition has been changed in a schema
2595
transaction, or when a committed table definition is
2596
merged with table definitions from other nodes during
2601
<p><c>where_to_read</c>.This argument returns the node
2602
where the table can be read. If the value <c>nowhere</c>
2603
is returned, the table is not loaded, or it resides at a
2604
remote node which is not running.
2608
<p><c>where_to_write</c>. This argument returns a list
2609
of the nodes that currently hold an active replica of
2614
<p><c>wild_pattern</c>. This argument returns a
2615
structure which can be given to the various match
2616
functions for a certain table. A record tuple is where all
2617
record fields have the value <c>'_'</c>.
2624
<name>transaction(Fun [[, Args], Retries]) -> {aborted, Reason} | {atomic, ResultOfFun}</name>
2625
<fsummary>Execute a transaction.</fsummary>
2627
<p>This function executes the functional object <c>Fun</c>
2628
with arguments <c>Args</c> as a transaction.
2630
<p>The code which executes inside the transaction
2631
can consist of a series of table manipulation functions.
2632
If something goes wrong inside the transaction as a result of a
2633
user error or a certain table not being available, the
2634
entire transaction is aborted and the function
2635
<c>transaction/1</c> returns the tuple
2636
<c>{aborted, Reason}</c>.
2638
<p>If all is well, <c>{atomic, ResultOfFun}</c> is returned where
2639
<c>ResultOfFun</c> is the value of the last expression in
2642
<p>A function which adds a family to the database can be
2643
written as follows if we have a structure <c>{family, Father, Mother, ChildrenList}</c>:
2646
add_family({family, F, M, Children}) ->
2647
ChildOids = lists:map(fun oid/1, Children),
2649
mnesia:write(F#person{children = ChildOids},
2650
mnesia:write(M#person{children = ChildOids},
2651
Write = fun(Child) -> mnesia:write(Child) end,
2652
lists:foreach(Write, Children)
2654
mnesia:transaction(Trans).
2656
oid(Rec) -> {element(1, Rec), element(2, Rec)}.
2658
<p>This code adds a set of people to the database. Running this code
2659
within one transaction will ensure that either the whole
2660
family is added to the database, or the whole transaction
2661
aborts. For example, if the last child is badly formatted,
2662
or the executing process terminates due to an
2663
<c>'EXIT'</c> signal while executing the family code, the
2664
transaction aborts. Accordingly, the situation where half a
2665
family is added can never occur.
2667
<p>It is also useful to update the database within a transaction
2668
if several processes concurrently update the same records.
2669
For example, the function <c>raise(Name, Amount)</c>, which
2670
adds <c>Amount</c> to the salary field of a person, should
2671
be implemented as follows:
2674
raise(Name, Amount) ->
2675
mnesia:transaction(fun() ->
2676
case mnesia:wread({person, Name}) of
2678
Salary = Amount + P#person.salary,
2679
P2 = P#person{salary = Salary},
2682
mnesia:abort("No such person")
2686
<p>When this function executes within a transaction,
2687
several processes running on different nodes can concurrently
2688
execute the <c>raise/2</c> function without interfering
2691
<p>Since Mnesia detects deadlocks, a transaction can be
2692
restarted any number of times. This function will attempt a restart as specified in
2693
<c>Retries</c>. <c>Retries</c> must
2694
be an integer greater than 0 or the atom <c>infinity</c>. Default is
2695
<c>infinity</c>.</p>
2699
<name>transform_table(Tab, Fun, NewAttributeList, NewRecordName) -> {aborted, R} | {atomic, ok} </name>
2700
<fsummary>Change format on all records in table. <c>Tab</c></fsummary>
2702
<p>This function applies the argument <c>Fun</c> to all
2703
records in the table. <c>Fun</c> is a function which takes a
2704
record of the old type and returns a transformed record of the
2705
new type. The <c>Fun</c> argument can also be the atom
2706
<c>ignore</c>, it indicates that only the meta data about the table will
2707
be updated. Usage of <c>ignore</c> is not recommended but included
2708
as a possibility for the user do to his own transform.
2709
<c>NewAttributeList</c> and <c>NewRecordName</c>
2710
specifies the attributes and the new record type of converted
2711
table. Table name will always remain unchanged, if the
2712
record_name is changed only the mnesia functions which
2713
uses table identifiers will work, e.g. <c>mnesia:write/3</c>
2714
will work but <c>mnesia:write/1</c> will not.</p>
2718
<name>transform_table(Tab, Fun, NewAttributeList) -> {aborted, R} | {atomic, ok} </name>
2719
<fsummary>Change format on all records in table. <c>Tab</c></fsummary>
2721
<p>Invokes <c>mnesia:transform_table(Tab, Fun, NewAttributeList, RecName)</c>
2722
where <c>RecName</c> is <c>mnesia:table_info(Tab, record_name)</c>.</p>
2726
<name>traverse_backup(Source, [SourceMod,] Target, [TargetMod,] Fun, Acc) -> {ok, LastAcc} | {error, Reason}</name>
2727
<fsummary>Traversal of a backup.</fsummary>
2729
<p>With this function it is possible to iterate over a backup,
2730
either for the purpose of transforming it into a new backup,
2731
or just reading it. The arguments are explained briefly
2732
below. See the Mnesia User's Guide for additional
2735
<list type="bulleted">
2736
<item><c>SourceMod</c> and <c>TargetMod</c> are the names of
2737
the modules which actually access the backup
2740
<item><c>Source</c> and <c>Target</c> are opaque data used
2741
exclusively by the modules <c>SourceMod</c> and
2742
<c>TargetMod</c> for the purpose of initializing the
2745
<item><c>Acc</c> is an initial accumulator value.
2747
<item><c>Fun(BackupItems, Acc)</c> is applied to each item in
2748
the backup. The Fun must return a tuple
2749
<c>{BackupItems,NewAcc}</c>, where <c>BackupItems</c> is
2750
a list of valid backup items, and <c>NewAcc</c> is a new
2751
accumulator value. The returned backup items are written
2752
in the target backup.
2754
<item><c>LastAcc</c> is the last accumulator value. This is
2755
the last <c>NewAcc</c> value that was returned by <c>Fun</c>.
2761
<name>uninstall_fallback() -> ok | {error,Reason}</name>
2762
<fsummary>Uninstall a fallback.</fsummary>
2764
<p>Invokes <c>mnesia:uninstall_fallback([{scope, global}])</c>.</p>
2768
<name>uninstall_fallback(Args) -> ok | {error,Reason}</name>
2769
<fsummary>Uninstall a fallback.</fsummary>
2771
<p>This function is used to de-install a fallback before it
2772
has been used to restore the database. This is normally a
2773
distributed operation that is either performed on all
2774
nodes with disc resident schema or none. Uninstallation of
2775
fallbacks requires Erlang to be up and running on all
2776
involved nodes, but it does not matter if Mnesia is running
2777
or not. Which nodes that are considered as disc-resident
2778
nodes is determined from the schema info in the local
2781
<p><c>Args</c> is a list of the following tuples:
2783
<list type="bulleted">
2785
<p><c>{module, BackupMod}</c>.
2786
See <c>mnesia:install_fallback/2</c> about the
2790
<p><c>{scope, Scope}</c>
2791
See <c>mnesia:install_fallback/2</c> about the
2795
<p><c>{mnesia_dir, AlternateDir}</c>
2796
See <c>mnesia:install_fallback/2</c> about the
2803
<name>unsubscribe(EventCategory)</name>
2804
<fsummary>Subscribe to events of type <c>EventCategory</c>.</fsummary>
2806
<p>Stops sending events of type
2807
<c>EventCategory</c> to the caller.</p>
2811
<name>wait_for_tables(TabList,Timeout) -> ok | {timeout, BadTabList} | {error, Reason} </name>
2812
<fsummary>Wait for tables to be accessible.</fsummary>
2814
<p>Some applications need to wait for certain tables to
2815
be accessible in order to do useful work.
2816
<c>mnesia:wait_for_tables/2</c> hangs until all tables in the
2817
<c>TabList</c> are accessible, or until <c>timeout</c> is
2822
<name>wread({Tab, Key}) -> transaction abort | RecordList </name>
2823
<fsummary>Read records with given key.</fsummary>
2825
<p>Invoke <c>mnesia:read(Tab, Key, write)</c>.</p>
2829
<name>write(Record) -> transaction abort | ok </name>
2830
<fsummary>Writes a record into the database.</fsummary>
2832
<p>Invoke <c>mnesia:write(Tab, Record, write)</c> where
2833
<c>Tab</c> is <c>element(1, Record)</c>.</p>
2837
<name>write(Tab, Record, LockKind) -> transaction abort | ok </name>
2838
<fsummary>Write an record into the database.</fsummary>
2840
<p>Writes the record <c>Record</c> to the table <c>Tab</c>.
2842
<p>The function returns <c>ok</c>, or aborts if an error
2843
occurs. For example, the transaction aborts if no
2844
<c>person</c> table exists.
2846
<p>The semantics of this function is context sensitive. See
2847
<c>mnesia:activity/4</c> for more information. In transaction
2848
context it acquires a lock of type <c>LockKind</c>. The
2849
following lock types are supported: <c>write</c> and
2850
<c>sticky_write</c>.</p>
2854
<name>write_lock_table(Tab) -> ok | transaction abort</name>
2855
<fsummary>Set write lock on an entire table.</fsummary>
2857
<p>Invokes <c>mnesia:lock({table, Tab}, write)</c>.</p>
2863
<title>Configuration Parameters</title>
2864
<p>Mnesia reads the following application configuration
2866
<list type="bulleted">
2868
<p><c>-mnesia access_module Module</c>. The
2869
name of the Mnesia activity access callback module. The default is
2874
<p><c>-mnesia auto_repair true | false</c>. This flag controls
2875
whether Mnesia will try to automatically repair
2876
files that have not been properly closed. The default is
2881
<p><c>-mnesia backup_module Module</c>. The
2882
name of the Mnesia backup callback module. The default is
2883
<c>mnesia_backup</c>.
2887
<p><c>-mnesia debug Level</c>
2888
Controls the debug level of Mnesia.
2889
Possible values are:</p>
2891
<tag><c>none</c></tag>
2893
<p>No trace outputs at all. This is the default setting.
2896
<tag><c>verbose</c></tag>
2898
<p>Activates tracing of important debug events. These
2899
debug events generate <c>{mnesia_info, Format, Args}</c>
2900
system events. Processes may subscribe to these events with
2901
<c>mnesia:subscribe/1</c>. The events are always sent to Mnesia's
2905
<tag><c>debug</c></tag>
2907
<p>Activates all events at the verbose level plus full
2908
trace of all debug events. These debug events generate
2909
<c>{mnesia_info, Format, Args}</c> system events. Processes may
2910
subscribe to these events with <c>mnesia:subscribe/1</c>. The
2911
events are always sent to the Mnesia event handler. On this
2912
debug level, the Mnesia event handler starts subscribing to
2913
updates in the schema table.
2916
<tag><c>trace</c></tag>
2918
<p>Activates all events at the level debug. On this
2919
debug level, the Mnesia event handler starts subscribing to
2920
updates on all Mnesia tables. This level is only intended
2921
for debugging small toy systems since many large
2922
events may be generated.
2925
<tag><c>false</c></tag>
2927
<p>An alias for none.
2930
<tag><c>true</c></tag>
2932
<p>An alias for debug.
2938
<p><c>-mnesia core_dir Directory</c>. The name of the
2939
directory where Mnesia core files is stored or
2940
false. Setting it implies that also ram only nodes, will
2941
generate a core file if a crash occurs. </p>
2944
<p><c>-mnesia dc_dump_limit Number</c>.
2945
Controls how often <c>disc_copies</c> tables are dumped from memory.
2946
Tables are dumped when
2947
<c>filesize(Log) > (filesize(Tab)/Dc_dump_limit)</c>.
2948
Lower values reduces cpu overhead but increases disk space and
2949
startup times. The default is 4.</p>
2952
<p><c>-mnesia dir Directory</c>. The name of the directory
2953
where all Mnesia data is stored. The name of the directory must
2954
be unique for the current node. Two nodes may, under no
2955
circumstances, share the same Mnesia directory. The results are
2956
totally unpredictable.</p>
2959
<p><c>-mnesia dump_log_load_regulation true | false</c>.
2960
Controls if the log dumps should be performed as fast as
2961
possible or if the dumper should do its own load
2962
regulation. This feature is temporary and will disappear in a
2963
future release. The default is <c>false</c>.
2967
<p><c>-mnesia dump_log_update_in_place true | false</c>.
2968
Controls if log dumps are performed on a copy of
2969
the original data file, or if the log dump is
2970
performed on the original data file. The default is <c>true</c></p>
2973
<p><c>-mnesia dump_log_write_threshold Max</c>, where
2974
<c>Max</c> is an integer which specifies the maximum number of writes
2975
allowed to the transaction log before a new dump of the log
2976
is performed. It defaults to 100 log writes.
2980
<p><c>-mnesia dump_log_time_threshold Max</c>,
2981
where <c>Max</c> is an integer which
2982
specifies the dump log interval in milliseconds. It defaults
2983
to 3 minutes. If a dump has not been performed within
2984
<c>dump_log_time_threshold</c> milliseconds, then a new dump is
2985
performed regardless of how many writes have been
2990
<p><c>-mnesia event_module Module</c>. The
2991
name of the Mnesia event handler callback module. The default is
2992
<c>mnesia_event</c>.
2996
<p><c>-mnesia extra_db_nodes Nodes</c> specifies a list of
2997
nodes, in addition to the ones found in the schema, with which
2998
Mnesia should also establish contact. The default value
2999
is the empty list <c>[]</c>.
3003
<p><c>-mnesia fallback_error_function {UserModule, UserFunc}</c>
3004
specifies a user supplied callback function
3005
which will be called if a fallback is installed and mnesia
3006
goes down on another node. Mnesia will call the function
3007
with one argument the name of the dying node, e.g.
3008
<c>UserModule:UserFunc(DyingNode)</c>.
3009
Mnesia should be restarted or else
3010
the database could be inconsistent.
3011
The default behaviour is to terminate mnesia.
3015
<p><c>-mnesia max_wait_for_decision Timeout</c>. Specifies
3016
how long Mnesia will wait for other nodes to share their
3017
knowledge regarding the outcome of an unclear transaction. By
3018
default the <c>Timeout</c> is set to the atom
3019
<c>infinity</c>, which implies that if Mnesia upon startup
3020
encounters a "heavyweight transaction" whose outcome is
3021
unclear, the local Mnesia will wait until Mnesia is started
3022
on some (in worst cases all) of the other nodes that were
3023
involved in the interrupted transaction. This is a very rare
3024
situation, but when/if it happens, Mnesia does not guess if
3025
the transaction on the other nodes was committed or aborted.
3026
Mnesia will wait until it knows the outcome and then act
3029
<p>If <c>Timeout</c> is set to an integer value in
3030
milliseconds, Mnesia will force "heavyweight transactions"
3031
to be finished, even if the outcome of the transaction for
3032
the moment is unclear. After <c>Timeout</c> milliseconds,
3033
Mnesia will commit/abort the transaction and continue with
3034
the startup. This may lead to a situation where the
3035
transaction is committed on some nodes and aborted on other
3036
nodes. If the transaction was a schema transaction, the
3037
inconsistency may be fatal.
3041
<p><c>-mnesia no_table_loaders NUMBER</c> specifies the number of
3042
parallel table loaders during start. More loaders can be good if the
3043
network latency is high or if many tables contains few records.
3044
The default value is <c>2</c>.
3048
<p><c>-mnesia schema_location Loc</c> controls where
3049
Mnesia will look for its schema. The parameter
3050
<c>Loc</c> may be one of the following atoms: </p>
3052
<tag><c>disc</c></tag>
3054
<p>Mandatory disc. The schema is assumed to be located
3055
in the Mnesia directory. If the schema cannot be found,
3056
Mnesia refuses to start. This is the old behavior.
3059
<tag><c>ram</c></tag>
3061
<p>Mandatory RAM. The schema resides in RAM
3062
only. At start-up, a tiny new schema is generated. This
3063
default schema just contains the definition of the schema
3064
table and only resides on the local node. Since no other
3065
nodes are found in the default schema, the configuration
3066
parameter <c>extra_db_nodes</c> must be used in
3068
node share its table definitions with other nodes. (The
3069
<c>extra_db_nodes</c> parameter may also be used on disc based nodes.)
3072
<tag><c>opt_disc</c></tag>
3074
<p>Optional disc. The schema may reside either on disc
3075
or in RAM. If the schema is found on disc, Mnesia starts as a
3076
disc based node and the storage type of the schema table is
3077
<c>disc_copies</c>. If no schema is found on disc, Mnesia starts
3078
as a disc-less node and the storage type of the schema table is
3079
<c>ram_copies</c>. The default value for the application parameter
3086
<p>First the SASL application parameters are checked, then
3087
the command line flags are checked, and finally, the default
3093
<title>See Also</title>
3094
<p>mnesia_registry(3), mnesia_session(3), qlc(3),
3095
dets(3), ets(3), disk_log(3), application(3)