Skip to content

Commit 6c47055

Browse files
committed
Merge pull request sorintlab#516 from sgotti/report_and_save_postgres_binary_version
*: report and save postgres binary version
2 parents 0299758 + be92998 commit 6c47055

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

cmd/keeper/cmd/keeper.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,6 @@ func (p *PostgresKeeper) createPGParameters(db *cluster.DB) common.Parameters {
336336
for _, synchronousStandby := range db.Spec.ExternalSynchronousStandbys {
337337
synchronousStandbys = append(synchronousStandbys, synchronousStandby)
338338
}
339-
// TODO(sgotti) Find a way to detect the pg major version also
340-
// when the instance is empty. Parsing the postgres --version
341-
// is not always reliable (for example we can get `10devel` for
342-
// development version).
343-
// Now this will lead to problems starting the instance (or
344-
// warning reloading the parameters) with postgresql < 9.6
345339

346340
// We deliberately don't use postgres FIRST or ANY methods with N
347341
// different than len(synchronousStandbys) because we need that all the
@@ -533,11 +527,21 @@ func (p *PostgresKeeper) updateKeeperInfo() error {
533527
return nil
534528
}
535529

530+
maj, min, err := p.pgm.BinaryVersion()
531+
if err != nil {
532+
// in case we fail to parse the binary version then log it and just report maj and min as 0
533+
log.Warnf("failed to get postgres binary version: %v", err)
534+
}
535+
536536
keeperInfo := &cluster.KeeperInfo{
537-
InfoUID: common.UID(),
538-
UID: keeperUID,
539-
ClusterUID: clusterUID,
540-
BootUUID: p.bootUUID,
537+
InfoUID: common.UID(),
538+
UID: keeperUID,
539+
ClusterUID: clusterUID,
540+
BootUUID: p.bootUUID,
541+
PostgresBinaryVersion: cluster.PostgresBinaryVersion{
542+
Maj: maj,
543+
Min: min,
544+
},
541545
PostgresState: p.getLastPGState(),
542546
}
543547

cmd/sentinel/cmd/sentinel.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ func (s *Sentinel) updateKeepersStatus(cd *cluster.ClusterData, keepersInfo clus
248248
s.CleanKeeperError(keeperUID)
249249
// Update keeper status infos
250250
k.Status.BootUUID = ki.BootUUID
251+
k.Status.PostgresBinaryVersion.Maj = ki.PostgresBinaryVersion.Maj
252+
k.Status.PostgresBinaryVersion.Min = ki.PostgresBinaryVersion.Min
251253
}
252254
}
253255

internal/cluster/cluster.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ type FollowConfig struct {
9595
StandbySettings *StandbySettings `json:"standbySettings,omitempty"`
9696
}
9797

98+
type PostgresBinaryVersion struct {
99+
Maj int
100+
Min int
101+
}
102+
98103
type ClusterPhase string
99104

100105
const (
@@ -530,6 +535,8 @@ type KeeperStatus struct {
530535
LastHealthyTime time.Time `json:"lastHealthyTime,omitempty"`
531536

532537
BootUUID string `json:"bootUUID,omitempty"`
538+
539+
PostgresBinaryVersion PostgresBinaryVersion `json:"postgresBinaryVersion,omitempty"`
533540
}
534541

535542
type Keeper struct {

internal/cluster/member.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type KeeperInfo struct {
4747
ClusterUID string `json:"clusterUID,omitempty"`
4848
BootUUID string `json:"bootUUID,omitempty"`
4949

50+
PostgresBinaryVersion PostgresBinaryVersion `json:"postgresBinaryVersion,omitempty"`
51+
5052
PostgresState *PostgresState `json:"postgresState,omitempty"`
5153
}
5254

0 commit comments

Comments
 (0)