Using sockets for database#
 Available on all plans
 self-hosted deployments
Mattermost requires a database back-end, and PostgreSQL is our database of choice. In this document let’s understand how you can use sockets for setting up the database.
Install and configure PostgreSQL.
Choose between TCP or UNIX Socket, and jump to the corresponding section.
With TCP socket#
Create the new user while connecting to the server as
postgresuser (you will be prompted for a password for the new user):sudo -u postgres createuser -P mmuserCreate the Mattermost database, owned by
mmuseruser:sudo -u postgres createdb -O mmuser mattermostdbIn the connections and authentications section, set the
listen_addresslist line per your needs:/var/lib/postgres/data/postgresql.conf listen_address = 'localhost,my_local_ip_address'
You can use ‘*’ to listen on all available addresses.
Then add a line like the following to the authentication config:
/var/lib/postgres/data/pg_hba.conf # TYPE DATABASE USER ADDRESS METHOD # IPv4 local connections: host all all ip_address/32 md5
Run the setup using:
psql --host=ip_address --dbname=mattermostdb --username=mmuser --password
With Unix socket#
Create the new user while connecting to the server as
postgresuser:sudo -u postgres createuser mattermost
Create the Mattermost database, owned by
mattermostuser:sudo -u postgres createdb -O mattermost mattermostdb
Setup the Unix socket by adding the following line to
/var/lib/postgres/data/pg_hba.conf:local mattermostdb mattermost peer
Restart postgresql.service.
Run the setup using:
sudo -u mattermost psql --dbname=mattermostdb
Configuring Mattermost#
Mattermost is configured in
/etc/webapps/mattermost/config.json. Strings need to be quoted.Set
DriverNametopostgres.Set
DataSource:TCP socket:
postgres://mmuser:mmuser_password@127.0.0.1:5432/mattermostdb?sslmode=disable&connect_timeout=10Unix socket:
postgres:///mattermostdb?host=/run/postgresql, wheremattermostdbis the name of the database and/run/postgresqlis the directory containing the Unix socket.