Mattermost, Inc.

Getting "dial tcp 127.0.0.1:5432" error on EC2 instance after editing config.json

Summary

There is another question like this in the forum but it doesn’t answer my question, that one being a Docker question.
In my Amazon EC2 container, after configuring Postgres RDS connection in config.json, when I start the service, no matter what I do, it still tries to connect to Postgres on 127.1:5432 .

Steps to reproduce

I tried configuration, according to the guide, by editing config.json. Mine looks sorta like this:

cat /opt/mattermost/config/config.json | grep postgres
        "DriverName": "postgres",
        "DataSource": "postgres:SECRET@mattermost.SECRET.us-east-1.rds.amazonaws.com:5432/mattermost?sslmode=disable&connect_timeout=10",

I also tried the suggestion from that other Docker thread, like so, but this didn’t override it either.

export MM_USERNAME=postgres
export MM_PASSWORD=SECRET
export DB_HOST=mattermost.SECRET.us-east-1.rds.amazonaws.com
export DB_PORT=5432
export MM_DBNAME=mattermost
export MM_SQLSETTINGS_DATASOURCE="postgres://$MM_USERNAME:$MM_PASSWORD@$DB_HOST:$DB_PORT/$MM_DBNAME?sslmode=disable&connect_timeout=10"
cd /opt/mattermost/
sudo -u mattermost ./bin/mattermost

Expected behavior

During initial start of the server, I just expected it to connect to my Postgres RDS instance.

Observed behavior

During startup, the log looks like this:

**ubuntu@ip-SECRET** : **/opt/mattermost** $ ./entryPoint.sh 

{"level":"info","ts":1585277262.8005755,"caller":"utils/i18n.go:83"
,"msg":"Loaded system translations","for locale":"en","from locale":"/opt/mattermost/i18n/en.json"}
{"level":"info","ts":1585277262.8008142,"caller":"app/server_app_adapters.go:58"
,"msg":"Server is initializing..."}
{"level":"info","ts":1585277262.8097615,"caller":"sqlstore/supplier.go:221"
,"msg":"Pinging SQL","database":"master"}
{"level":"error","ts":1585277262.8409588,"caller":"sqlstore/supplier.go:233"
,"msg":"Failed to ping DB","error":"dial tcp 127.0.0.1:5432: connect: connection refused","retrying in seconds":10}

Using server version 5.21.0

UPDATE:
I discovered that I had to have postres:// in the front of the db url.

Now I am getting this error. Trying to figure it out:

"caller":"sqlstore/supplier.go:233","msg":"Failed to ping DB","error":"dial tcp 172.30.3.5:5432: i/o timeout","retrying in seconds":10

I got it to work. I switched to a MySQL RDS instance and it had no issue.

Thanks. I hope this helps someone else.