"Failed to ping DB" when trying to start mattermost server


Greetings! I am following this guide to set up mattermost(5.27.0) on a Microsoft Azure server with centos8. I was trying to use:

sudo -u mattermost ./bin/mattermost

to start the server but I was unable to ping the database. (Every previous steps in the guide worked fine).

My config.json:

"DriverName": "postgres",
"DataSource": "postgres://mmuser:mmuser_pw@\u0026connect_timeout=10",

Expected behavior

Should be able to connect successfully.

Observed behavior

sudo -u mattermost ./bin/mattermost
{"level":"info","msg":"Server is initializing..."}
{"level":"info","ts":1602793035.114669,"caller":"app/web_hub.go:83","msg":"Starting websocket hubs","number_of_hubs":2}
{"level":"info","ts":1602793035.1163628,"caller":"utils/i18n.go:83","msg":"Loaded system translations","for locale":"en","from locale":"/opt/mattermost/i18n/en.json"}
{"level":"info","ts":1602793035.1180053,"caller":"sqlstore/supplier.go:227","msg":"Pinging SQL","database":"master"}
{"level":"error","ts":1602793045.1183646,"caller":"sqlstore/supplier.go:239","msg":"Failed to ping DB","error":"dial tcp i/o timeout","retrying in seconds":10}

Hi! Are you using a firewall such as UFW? If you are, could you verify that the port you are running your database on it open, and unrestricted and that your database user is configured correctly to connect to the Postgres database with the external IP?

In addition, are you connecting to a database that is located on the same server as your Mattermost instance, or is this a remote database?

1 Like

Hello! Thanks for your response! To address your questions:

  • There is currently no firewall on the server.

  • The database and mattermost instance are located on the same server and I can connect to the postgres database with mmuser. Should I change the ip address to something else in my config.json?

Sorry if the question seem basic, I’m pretty new to this.

@markll80 I’m thinking this may be a networking error.

If you are hosting the Mattermost instance on the same server as the database, but you have the configured database user attempting to connect to the database as if it was connecting to a remote database on a different server (which is done by using the public IP address), then you may be having a routing conflict. This would be due to the Mattermost database connection agent attempting to connect to itself remotely, when instead, you should be using a database user that is configured to only be able to connect from the localhost.

For example, with MySQL, the database user that I am using, is mmuser@localhost. This means that the database user is directly connecting back to the local database, which is knows due to being an account connecting at the localhost, is on the local machine.

I hope this makes sense and helps, let me know if it works out, and if it doesn’t, I’ll continue to help you troubleshoot!

1 Like

Also, I ran a nmap scan on the IP address you included in the sample code, and it doesn’t have any ports open, so could not possibly connect to the database even if everything else was setup correctly. Is the IP in the code example you initially provided the actual production IP address, or just a placeholder?

Yes changing the ip address to locahost and removing the port number works for me, thank you very much for your help!

1 Like

I’m glad you got it working and glad to provide assistance, anytime! :slight_smile:

1 Like