Backport #28708 by wxiaoguang Regression of #27723 Fix #28705 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>tags/v1.21.4
@@ -168,7 +168,7 @@ func getPostgreSQLConnectionString(dbHost, dbUser, dbPasswd, dbName, dbsslMode s | |||
RawQuery: dbParam, | |||
} | |||
query := connURL.Query() | |||
if dbHost[0] == '/' { // looks like a unix socket | |||
if strings.HasPrefix(dbHost, "/") { // looks like a unix socket | |||
query.Add("host", dbHost) | |||
connURL.Host = ":" + port | |||
} |
@@ -65,6 +65,10 @@ func Test_getPostgreSQLConnectionString(t *testing.T) { | |||
SSLMode string | |||
Output string | |||
}{ | |||
{ | |||
Host: "", // empty means default | |||
Output: "postgres://:@127.0.0.1:5432?sslmode=", | |||
}, | |||
{ | |||
Host: "/tmp/pg.sock", | |||
User: "testuser", |