diff --git a/pkg/dbclient/client.go b/pkg/dbclient/client.go index a6644d8..a0637dc 100644 --- a/pkg/dbclient/client.go +++ b/pkg/dbclient/client.go @@ -58,7 +58,13 @@ func (p *client) getDB(dbname string) (*sql.DB, error) { return nil, err } u.Path = "/" + dbname - return sql.Open("postgres", u.String()) + // thayward: Why is this creating a new pool instead of using p.DB? + db, err := sql.Open("postgres", u.String()) + if err != nil { + return nil, err + } + db.SetConnMaxIdleTime(time.Minute) + return db, nil } type Config struct { @@ -98,6 +104,7 @@ func newPostgresClient(ctx context.Context, cfg Config) (*client, error) { if err != nil { return nil, err } + db.SetConnMaxIdleTime(time.Minute) // create a new connection to the database to run admin commands. @@ -111,6 +118,7 @@ func newPostgresClient(ctx context.Context, cfg Config) (*client, error) { if err != nil { return nil, err } + adminDB.SetConnMaxIdleTime(time.Minute) if err := adminDB.PingContext(ctx); err != nil { adminDB.Close() diff --git a/pkg/pgctl/utils.go b/pkg/pgctl/utils.go index 01b24f7..6fdc167 100644 --- a/pkg/pgctl/utils.go +++ b/pkg/pgctl/utils.go @@ -8,6 +8,7 @@ import ( "io" "net/url" "os/exec" + "time" "github.com/go-logr/logr" ) @@ -96,6 +97,7 @@ func getDB(dsn string, db *sql.DB) (*sql.DB, error) { if db, err = sql.Open("postgres", dsn); err != nil { return nil, err } + db.SetConnMaxIdleTime(time.Minute) } if err = db.Ping(); err != nil { return nil, err