Installing PostgreSQL database
Log in to the server that will host the database, and open a terminal window.
Install PostgreSQL.
sudo yum install postgresql-server postgresql-contrib
Confirm this version is PostgreSQL version 10 or higher. You can do this by running psql -V
. If this isn’t version 10 or higher you can reference the PostgreSQL documentation [here](https://www.postgresql.org/download/linux/redhat/) to install an updated version of PostgreSQL.
Initialize the database.
sudo postgresql-setup initdb
Set PostgreSQL to start on boot.
sudo systemctl enable postgresql
Start the PostgreSQL server.
sudo systemctl start postgresql
Switch to the postgres Linux user account that was created during the installation.
sudo -iu postgres
Start the PostgreSQL interactive terminal.
psql
Create the Mattermost database.
postgres=# CREATE DATABASE mattermost WITH ENCODING 'UTF8' LC_COLLATE='en_US.UTF-8' LC_CTYPE='en_US.UTF-8' TEMPLATE=template0;
Create the Mattermost user mmuser.
postgres=# CREATE USER mmuser WITH PASSWORD 'mmuser-password';
Note
Use a password that is more secure than ‘mmuser-password’.
Grant the user access to the Mattermost database.
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
Exit the PostgreSQL interactive terminal.
postgres=# \q
Log out of the postgres account.
exit
(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/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.
Open
/var/lib/pgsql/data/postgresql.conf
as root in a text editor.Find the following line:
#listen_addresses = 'localhost'
Uncomment the line and change
localhost
to*
:
listen_addresses = '*'
Restart PostgreSQL for the change to take effect:
sudo systemctl restart postgresql
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:
Open
/var/lib/pgsql/data/pg_hba.conf
as root in a text editor.Find the following lines:
local all all peer
host all all ::1/128 ident
Change
peer
andident
totrust
:
local all all trust
host all all ::1/128 trust
If the Mattermost server and the database are on different machines:
Open
/var/lib/pgsql/data/pg_hba.conf
as root in a text editor.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
Reload PostgreSQL:
sudo systemctl reload postgresql
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
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.