Prepare your Mattermost database

plans-img Available on all plans

deployment-img self-hosted deployments


You need one database: either PostgreSQL or MySQL. See the database software documentation for details on database version support.

Install and set up a PostgreSQL database for use by the Mattermost server. These instructions assume that the IP address of this server is

  1. Log in to the server that will host the database, and install PostgreSQL. See the PostgreSQL documentation for details. When the installation is complete, the PostgreSQL server is running, and a Linux user account called postgres has been created.

  2. Access PostgreSQL with one of the following options:

  • sudo --login --user postgres then psql OR

  • sudo -u postgres psql

  1. Create the Mattermost database by running postgres=# CREATE DATABASE mattermost;.

  2. Create the Mattermost user mmuser by running postgres=# CREATE USER mmuser WITH PASSWORD 'mmuser-password';.

  • Use a password that’s more secure than mmuser-password.

  1. Grant the user access to the Mattermost database by running postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;.

  2. Exit the PostgreSQL interactive terminal by running postgres=# \q.

  3. Log out of the postgres account by running exit.

  4. (Optional) If you use separate servers for your database and the Mattermost server, you may allow PostgreSQL to listen on all assigned IP addresses by opening /etc/postgresql/{version}/main/postgresql.conf as root in a text editor, and replacing {version} with the version of PostgreSQL that’s currently running. As a best practice, ensure that only the Mattermost server is able to connect to the PostgreSQL port using a firewall.

  1. Find the following line: #listen_addresses = 'localhost'

  2. Uncomment the line and change localhost to *: listen_addresses = '*'

  3. Restart PostgreSQL for the change to take effect by running sudo systemctl restart postgresql.

  1. Modify the file pg_hba.conf to allow the Mattermost server to communicate with the database.

    If the Mattermost server and the database are on the same machine:

    1. Open /etc/postgresql/{version}/main/pg_hba.conf as root in a text editor.

    2. Find the following lines:

    local   all             all                        peer

    host    all             all         ::1/128        ident

    1. Change peer and ident to trust:

    local   all             all                        trust

    host    all             all         ::1/128        trust

    If the Mattermost server and the database are on different machines:

    1. Open /etc/postgresql/{version}/main/pg_hba.conf in a text editor as root user.

    2. Add the following line to the end of the file, where {mattermost-server-IP} is the IP address of the Mattermost server: host all all {mattermost-server-IP}/32 md5.

  2. Reload PostgreSQL by running sudo systemctl reload postgresql.

  3. Verify that you can connect with the user mmuser.

  • If the Mattermost server and the database are on the same machine, use the following command: psql --dbname=mattermost --username=mmuser --password

  • If the Mattermost server is on a different machine, log into that machine and use the following command: psql --host={postgres-server-IP} --dbname=mattermost --username=mmuser --password


You might have to install the PostgreSQL client software to use the command.

The PostgreSQL interactive terminal starts. To exit the PostgreSQL interactive terminal, type \q and press Enter on Windows or Linux, or on Mac.

When the PostgreSQL database is installed, and the initial setup complete, you can install the Mattermost server.