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
postgres
user (you will be prompted for a password for the new user):sudo -u postgres createuser -P mmuser
Create the Mattermost database, owned by
mmuser
user:sudo -u postgres createdb -O mmuser mattermostdb
In the connections and authentications section, set the
listen_address
list 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
postgres
user:sudo -u postgres createuser mattermost
Create the Mattermost database, owned by
mattermost
user: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
DriverName
topostgres
.Set
DataSource
:TCP socket:
postgres://mmuser:mmuser_password@127.0.0.1:5432/mattermostdb?sslmode=disable&connect_timeout=10
Unix socket:
postgres:///mattermostdb?host=/run/postgresql
, wheremattermostdb
is the name of the database and/run/postgresql
is the directory containing the Unix socket.