Skip to content

Commit

Permalink
fix: confirm initial database connectivity (#314)
Browse files Browse the repository at this point in the history
- adding db.Ping() call to confirm actual connection to the database to
  report issues with connectivity as early as possible

Co-authored-by: Kyle Johnson <kjohnson@gnulnx.net>
  • Loading branch information
nejec and kylejohnson authored Jul 14, 2023
1 parent ffdd7fd commit b33fe39
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions postgresql/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ func (c *Client) Connect() (*DBConnection, error) {
} else {
db, err = postgres.Open(context.Background(), dsn)
}

if err == nil {
err = db.Ping()
}
if err != nil {
errString := strings.Replace(err.Error(), c.config.Password, "XXXX", 2)
return nil, fmt.Errorf("Error connecting to PostgreSQL server %s (scheme: %s): %s", c.config.Host, c.config.Scheme, errString)
Expand Down

0 comments on commit b33fe39

Please sign in to comment.