Configuration in a database
You can use the database as the single source of truth for the active configuration of your Mattermost installation. This changes the Mattermost binary from reading the default
config.json file to reading the configuration settings stored within a configuration table in the database.
Benefits to using this option:
Conveniently manage configuration changes directly from the System Console, even in High Availability deployments and read-only containerized environments.
Ensure all servers in a High Availability deployment have the same configuration, even when new servers are added to the cluster.
Automatically deploy SAML certificates and keys to all servers in the cluster.
Note that once you start using configuration in the database, you shouldn’t manually edit the active configuration row. You should edit or update the configuration in one of the following ways:
Use the System Console to make changes to the configuration.
mmctlto make changes to the configuration.
Stop any of the running mattermost-server instances and edit the active configuration row directly in the
The Mattermost server keeps active configuration in memory and writes new ones to the database only when there is a change. This way we avoid polling the database to process changes to the configuration. Publishing the changes to the cluster are handled by the application itself.
How to migrate configuration to the database
These instructions cover migrating the Mattermost configuration to the database and updating your
systemd configuration to load it from the database.
These instructions assume you have Mattermost server installed at
/opt/mattermost. If you’re running Mattermost in a different directory you’ll have to modify the paths to match your environment.
Get your database connection string
The first step is to get your master database connection string. We recommend accessing your
config.json file to make a copy of the value in
SqlSettings.DataSource or your equivalent environment variable,
SqlSettings.DataSource does not start with
postgres://, then you have to add this line to the beginning based on the database in use. Also, if you see
\u0026, replace it with
Here is an example connection string:
Create an environment file
If you’re running Mattermost in a High Availability cluster, this step must be done on all servers in the cluster.
Create the file
/opt/mattermost/config/mattermost.environment to set the
MM_CONFIG environment variable to the database connection string. For example:
Run this command to verify the permissions on your Mattermost directory:
sudo chown -R mattermost:mattermost /opt/mattermost
Modify the Mattermost
First, find the
mattermost.service file using:
sudo systemctl status mattermost.service
The second line of output will have the location of the running
Loaded: loaded (/lib/systemd/system/mattermost.service; enabled; vendor preset: enabled)
Edit this file as root to add the below text just above the line that begins with
Here’s a complete
mattermost.service file with the
EnvironmentFile line added:
Migrate configuration from
You can use the mmctl config migrate command to migrate the configuration.
If you’re using a High Availability cluster, you only need to run this on a single server in the cluster.
When migrating config, Mattermost will incorporate configuration from any existing
MM_* environment variables set in the current shell. See Environment Variables
As with the environment file, you’ll have to escape any single quotes in the database connection string. Also, any existing SAML certificates will be migrated into the database as well so they are available for all servers in the cluster.
When configuration in the database is enabled, any changes to the configuration are recorded to the
ConfigurationFiles tables. Furthermore,
ClusterSettings.ReadOnlyConfig is ignored, enabling full use of the System Console.
If you have configuration settings that must be set on a per-server basis you should add them as environment variables to the
mattermost.environment file. These must be on their own line, and you must escape them properly.
Verify that the configuration was migrated correctly
Configurations are stored in the
Configurations table in the database. To verify that you’ve migrated the configuration successfully run this query:
SELECT * FROM Configurations WHERE Active=true;
There should be exactly one line returned, and the
Value field for that line should match your
systemd files and restart Mattermost
If you’re running Mattermost in High Availability this step must be run on all servers in the cluster.
Finally, run these commands to reload the daemon and restart Mattermost using the new
MM_CONFIG environment variable.
sudo systemctl daemon-reload
sudo systemctl restart mattermost
If you run into issues with your configuration in the database you can roll back to the
config.json file by commenting out the
MM_CONFIG line in
/opt/mattermost/config/mattermost.environment and restarting Mattermost with
systemctl restart mattermost.
Server fails to start
--disableconfigwatch flag while not actually pointing at a file will fail to start the server with an appropriate error message.