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

Commit

Permalink
SHOW returns a string not an int
Browse files Browse the repository at this point in the history
  • Loading branch information
JLockerman committed Aug 18, 2020
1 parent a96d677 commit 3ecc461
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/pgclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"runtime"
"strconv"

"github.com/prometheus/client_golang/prometheus"

Expand Down Expand Up @@ -130,11 +131,17 @@ func (cfg *Config) GetNumConnections() (min int, max int, numCopiers int, err er
return 0, 0, 0, err
}
defer func() { _ = conn.Close(context.Background()) }()
var maxStr string
row := conn.QueryRow(context.Background(), "SHOW max_connections")
err = row.Scan(&max)
err = row.Scan(&maxStr)
if err != nil {
return 0, 0, 0, err
}
max, err = strconv.Atoi(maxStr)
if err != nil {
log.Warn("err", err, "msg", "invalid value from postgres max_connections")
max = 100
}
if max <= 1 {
log.Warn("msg", "database can only handle 1 connection")
return 1, 1, 1, nil
Expand Down

0 comments on commit 3ecc461

Please sign in to comment.