Skip to content

Commit 91c5150

Browse files
Recover when connection cannot be established straight at startup
When the connection to the PostgreSQL instance cannot be established straight at startup, a race condition can happen when autoDiscoverDatabases is true. If discoverDatabaseDSNs fails, no dsn is set as the master database, and, if scrapeDSN succeeds, checkMapVersions will have omitted the default metrics in the server metric map. The metric map won't be updated unless the version returned by the PostgreSQL instance changes. With this patch, scrapeDSN won't be run unless discoverDatabaseDSNs succeeded and thus the race condition is eliminated. Signed-off-by: Yann Soubeyrand <[email protected]>
1 parent e2df41f commit 91c5150

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cmd/postgres_exporter/postgres_exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,12 +1503,12 @@ func (e *Exporter) discoverDatabaseDSNs() []string {
15031503
continue
15041504
}
15051505

1506-
dsns[dsn] = struct{}{}
15071506
server, err := e.servers.GetServer(dsn)
15081507
if err != nil {
15091508
log.Errorf("Error opening connection to database (%s): %v", loggableDSN(dsn), err)
15101509
continue
15111510
}
1511+
dsns[dsn] = struct{}{}
15121512

15131513
// If autoDiscoverDatabases is true, set first dsn as master database (Default: false)
15141514
server.master = true

0 commit comments

Comments
 (0)