Installing PostgreSQL Database Server

Install and set up the database for use by the Mattermost server. You can install either PostgreSQL or MySQL.

Assume that the IP address of this server is 10.10.10.1.

To install PostgreSQL on Ubuntu Server 18.04:

  1. Log in to the server that will host the database and issue the following command:

sudo apt install postgresql postgresql-contrib

When the installation is complete, the PostgreSQL server is running, and a Linux user account called postgres has been created.

  1. Log in to the postgres account.
sudo --login --user postgres
  1. Start the PostgreSQL interactive terminal.
psql
  1. Create the Mattermost database.
postgres=# CREATE DATABASE mattermost;
  1. Create the Mattermost user ‘mmuser’.

postgres=# CREATE USER mmuser WITH PASSWORD 'mmuser-password';

Note

Use a password that is more secure than ‘mmuser-password’.

  1. Grant the user access to the Mattermost database.
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
  1. Exit the PostgreSQL interactive terminal.
postgres=# \q
  1. Log out of the postgres account.
exit
  1. (Optional) If you use a different server for your database and the Mattermost app server, you may allow PostgreSQL to listen on all assigned IP Addresses. To do so, open /etc/postgresql/10/main/postgresql.conf as root in a text editor. 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'
  1. Uncomment the line and change localhost to *:
listen_addresses = '*'
  1. Restart PostgreSQL for the change to take effect:
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/10/main/pg_hba.conf as root in a text editor.
  2. Find the following line:
local   all             all                        peer
  1. Change peer to trust:
local   all             all                        trust

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

  1. Open /etc/postgresql/10/main/pg_hba.conf as root in a text editor.
  2. Add the following line to the end of the file, where {mattermost-server-IP} is the IP address of the machine that contains the Mattermost server.
host all all {mattermost-server-IP}/32 md5
  1. Reload PostgreSQL:
sudo systemctl reload postgresql
  1. Verify that you can connect with the user mmuser.
  1. If the Mattermost server and the database are on the same machine, use the following command:
psql --dbname=mattermost --username=mmuser --password
  1. 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

Note

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.

With the database installed and the initial setup complete, you can now install the Mattermost server.