Skip to content

SQLite

SQLite is an embedded SQL database stored in a single file. Like RocksDB, it runs inside the Stalwart process and needs no separate service. Its particular advantage is the single file, which is easy to copy and to inspect with standard tools. The file can also be replicated continuously to object storage with external tools such as Litestream. SQLite suits small single-node installations.

Only one process at a time opens an SQLite database, so several Stalwart nodes cannot share an SQLite data store. A cluster uses PostgreSQL, MySQL or FoundationDB instead.

The backend is selected with the Sqlite variant of the DataStore object (found in the WebUI under Settings › Storage › Data Store). path is the location of the database file, which is created if it does not exist. When path names an existing directory instead, the server stores the database in that directory as stalwart.db; this is what happens when the setup wizard carries the RocksDB data directory over after switching the data store to SQLite.

Database operations run on a pool of threads, whose size is set by poolWorkers. When the field is unset, the pool has as many threads as the host has processor cores, with a minimum of 4.

The number of open connections to the database is limited separately, by poolMaxConnections. When it is unset, it equals poolWorkers, kept between 4 and 16. This setting also affects memory, because each connection keeps its own page cache of 32 MiB. The connection count therefore determines part of the memory used by the server, as discussed in Tuning the data store.

The following data store uses the file /var/lib/stalwart/stalwart.db:

{
"@type": "Sqlite",
"path": "/var/lib/stalwart/stalwart.db"
}

When data is deleted, SQLite reuses the freed space for new data, but the database file itself does not shrink. To reduce its size, stop the server and run VACUUM on the file, as described in Data retention and reclaiming disk space.