Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 3ecc461

Browse files
committed
SHOW returns a string not an int
1 parent a96d677 commit 3ecc461

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/pgclient/client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"flag"
66
"fmt"
77
"runtime"
8+
"strconv"
89

910
"github.com/prometheus/client_golang/prometheus"
1011

@@ -130,11 +131,17 @@ func (cfg *Config) GetNumConnections() (min int, max int, numCopiers int, err er
130131
return 0, 0, 0, err
131132
}
132133
defer func() { _ = conn.Close(context.Background()) }()
134+
var maxStr string
133135
row := conn.QueryRow(context.Background(), "SHOW max_connections")
134-
err = row.Scan(&max)
136+
err = row.Scan(&maxStr)
135137
if err != nil {
136138
return 0, 0, 0, err
137139
}
140+
max, err = strconv.Atoi(maxStr)
141+
if err != nil {
142+
log.Warn("err", err, "msg", "invalid value from postgres max_connections")
143+
max = 100
144+
}
138145
if max <= 1 {
139146
log.Warn("msg", "database can only handle 1 connection")
140147
return 1, 1, 1, nil

0 commit comments

Comments
 (0)