Configuring a Socket-Based Database Connection for Mattermost (Self-Managed)

Disclaimer: This information is applicable only to Mattermost Professional. We still recommend running PostgreSQL on a dedicated server for optimal performance and reliability.

 

If you're running Mattermost and PostgreSQL on the same server, you can configure Mattermost to connect to the database over a Unix socket instead of the default TCP/IP connection. This can improve performance and security by avoiding network overhead and limiting exposure.


When to Use a Socket-Based Connection

  • Mattermost and PostgreSQL are running on the same machine.

  • You want to reduce overhead from TCP/IP networking.

  • You prefer not to expose the PostgreSQL port over the network.


Step 1: Find the PostgreSQL Socket Directory

  1. Log in to PostgreSQL with:

    sudo -u postgres psql
    
  2. Run the following command to identify the socket location:

    SHOW unix_socket_directories;
    

    This will typically return something like /var/run/postgresql.


Step 2: Update Mattermost Configuration

Update the SqlSettings.DataSource value in your config.json file or set it via an environment variable.

Example config.json:

"SqlSettings": {
    "DriverName": "postgres",
    "DataSource": "postgres://mmuser:mostest@/mattermost_test?host=/var/run/postgresql/"
}
  • Replace mmuser, mostest, mattermost_test, and /var/run/postgresql/ with your actual PostgreSQL user, password, database name, and socket path.

  • Note: The socket path must match the output from the earlier SHOW command.


Step 3: Verify Permissions

Make sure:

  • The Mattermost server user (e.g., mattermost) has read/write permissions to the socket directory.

  • The PostgreSQL configuration (pg_hba.conf) allows connections from Unix sockets.

Example line in pg_hba.conf:

local   all             all                                     md5

After any changes, reload PostgreSQL:

sudo systemctl reload postgresql

Final Step: Restart Mattermost

Once you've updated the configuration and verified permissions, restart the Mattermost server:

sudo systemctl restart mattermost

Troubleshooting Tips

  • Check Mattermost logs (/opt/mattermost/logs/) for database connection errors.

  • Verify PostgreSQL is accepting Unix socket connections.

  • Confirm file permissions on the socket path.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.