Database Backends
MongooseIM can work with several databases, both RDBMS (SQL) and NOSQL ones. Some of them require extra work before they can be used. For example the SQL databases require defining a schema. MongooseIM is tested with TravisCI, so the travis scripts can be used as a reference.
A Brief Overview
Data in MongooseIM is either transient or persistent:
- transient: volatile data changing often, such as session data, stream management data, and other in-memory data. These don't need any backup, since after a potential failure, they will naturally rebuild as clients reconnect.
- persistent: long-lived data, such as roster items, credentials, and chat archives. These absolutely need regular and tested backups.
Choosing a database for MongooseIM
Here is some general advice on the use of databases. Subsequent sections go into more depth on each database: what they are suitable for and how to set them up.
Transient data:
-
Mnesia - we highly recommend Mnesia (a highly available and distributed database) over Redis for storing transient data. Being an Erlang-based database, it's the default persistence option for most modules in MongooseIM. Warning: we strongly recommend keeping persistent data in an external DB (RDBMS or Riak) for production. Mnesia is not suitable for the volumes of persistent data which some modules may require. Sooner or later a migration will be needed which may be painful. It is possible to store all data in Mnesia, but only for testing purposes, not for any serious deployments.
-
Redis - A fantastic choice for storing live data. It's highly scalable and it can be easily shared by multiple MongooseIM nodes. Additionally, Redis' great performance makes it an excellent choice for storing
user session
data. We recommend caution, since it has not yet been widely tested in production.
Persistent Data:
-
RDBMS - MongooseIM has a strong backend support for relational databases. Reliable and battle proven, they are a great choice for regular MongooseIM use cases and features like
privacy lists
,vcards
,roster
,private storage
,last activity
andmessage archive
. Never loose your data. Use MySQL, MariaDB, PostgreSQL, or MS SQL Server. -
Riak KV - If you're planning to deploy a massive cluster, consider Riak KV as a potential storage backend solution. It offers high availability and fault tolerance which is exactly what you need for your distributed MongooseIM architecture. Use Riak KV with
privacy lists
,vcards
,roster
,private storage
,last activity
andmessage archive
. Erlang Solutions commercially supports Riak KV. -
Cassandra - Only for MAM (Message Archive Management).
-
ElasticSearch - Only for MAM (Message Archive Management).
User Data:
- LDAP - Used for: users, shared rosters, vCards
RDBMS
MySQL
Can be used for:
- users (credentials)
- vcards
- roster
- private storage
- privacy/block lists
- last activity
- mam (message archive management)
- muc_light rooms
Setup
The schema files can be found in the priv
directory.
The default schema is defined in the mysql.sql
file.
You can use the following command to apply it on localhost:
1 2 |
|
You should also configure the MySQL database in the mongooseim.toml
file.
Please refer to the RDBMS options for more information.
Version notice
The required minimum version of MySQL is 5.7.9
.
This is mainly to benefit from the JSON data type and the default settings which works out of the box with MongooseIM.
MySQL 8
In case of using MySQL version 8 and MongooseIM 3.6.2
or older the mysql_native_password
authentication plugin must be used as the default one.
Newer versions of MongooseIM works correctly with MySQL 8 and its default auth plugins.
PostgreSQL
Can be used for:
- users (credentials)
- vcards
- roster
- private storage
- privacy/block lists
- last activity
- mam (message archive management)
- muc_light rooms
Setup
The schema files can be found in the priv
directory.
The default schema is defined in the pg.sql
file.
You can use the following command to apply it on localhost:
1 2 |
|
mongooseim.toml
file.
Please refer to the RDBMS options
and general database options
for more information.
Microsoft SQL Server
Microsoft SQL Server, sometimes called MSSQL, or Azure SQL Database.
Warning: MongooseIM can only connect to MSSQL on Ubuntu Xenial x64.
This can be used for:
- users (credentials)
- vcards
- roster
- private storage
- privacy/block lists
- last activity
- mam (message archive management)
- muc_light rooms
Setup
MSSQL can be used from MongooseIM through the ODBC layer with FreeTDS driver, so you need them installed on your system.
1 2 3 4 5 6 7 8 |
|
Then you need to configure the connection.
Add your database (mongooseim
here) to the /etc/odbc.ini
or $HOME/.odbc.ini
file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Please amend the paths above to match your current OS if necessary.
For more details, please refer to the freetds.conf documentation and unixodbc documentation.
MongooseIM is built with ODBC support by default.
Deadlocks notice
If muc_light's backend is set to ODBC and there are many rooms created in parallel in your system,
there may be some deadlocks due to the READ_COMMITTED_SNAPSHOT
set to OFF
by default.
In this case we recommend to set this database property to ON
, this will enable row level locking which significantly reduces
deadlock chances around muc_light operations.
This property can be set by the following ALTER DATABASE
query:
1 |
|
The command above may take some time.
Then you need to import the SQL schema from mssql2012.sql
.
You can use a Microsoft's GUI tool (the provided .sql files should work with it) or isql, but after a slight modification of the dump file:
1 2 |
|
The final step is to configure mongooseim.toml
appropriately.
Set the following option in the general
section:
1 2 |
|
Configure the outgoing_pools.rdbms
section as follows:
1 2 3 4 5 6 |
|
NOSQL
Riak KV
Riak KV, for Key-Value, is technically supported by MongooseIM for versions upper than Riak KV 2.0. Erlang Solutions commercially supports Riak KV.
Can be used for:
- users (credentials)
- vcards
- roster
- private storage
- privacy/block lists
- last activity
- mam (message archive management)
Setup
We are using the Riak data types, so the minimal supported version is 2.0. To be able to store above persistent date one have to run the following command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
This will create bucket types, search schemas and indexes required for storing the above persitent data and it will activate them.
You should also configure Riak in the mongooseim.toml
file.
Please refer to the RDBMS options
and Riak options for more information.
Cassandra
Setup
This will prepare Cassandra for connection from MongooseIM. Make sure Cassandra is running, open a new terminal window and enter the following commands:
1 2 |
|
ElasticSearch
Can be used for:
- MAM (Message Archive Management)
Setup
Please note that MongooseIM has been tested to work properly with ElasticSearch version 5.6.9.
In order to use ElasticSearch as a MAM backend, you'll need to create required indexes and mappings. From the root of MongooseIM's repository run:
1 2 |
|
where $ELASTICSEARCH_URL
is a URL pointing to your ElasticSearch node's HTTP API endpoint.
Please refer to the advanced configuration page to check how to configure MongooseIM to connect to ElasticSearch node.
Redis
Can be used for:
- users sessions
Setup
Please refer to the Redis options for more information.
LDAP
Can be used for:
- users (credentials)
- shared roster
- vcard
Setup
Please refer to the LDAP options for more information.