@@ -61,15 +61,31 @@ var healthData *PostgreSQLHealthData
6161// getPostgresVersionInfo gets PostgreSQL version information
6262// and determines update status
6363func getPostgresVersionInfo () (string , bool , string ) {
64- // Get the version of PostgreSQL
65- out , err := exec .Command ("psql" , "--version" ).Output ()
66- if err != nil {
67- return "" , false , "Error getting version"
64+ var version string
65+
66+ if Connection != nil {
67+ var fullVersion string
68+ err := Connection .QueryRow ("SHOW server_version;" ).Scan (& fullVersion )
69+ if err == nil {
70+ version = strings .Split (fullVersion , " " )[0 ]
71+ }
6872 }
6973
70- // Parse the version
71- // Example output: psql (PostgreSQL) 13.3 (Ubuntu 13.3-1.pgdg20.04+1)
72- version := strings .Split (string (out ), " " )[2 ]
74+ if version == "" {
75+ out , err := exec .Command ("psql" , "--version" ).Output ()
76+ if err != nil {
77+ return "" , false , "Error getting version"
78+ }
79+
80+ // Parse the version
81+ // Example output: psql (PostgreSQL) 13.3 (Ubuntu 13.3-1.pgdg20.04+1)
82+ parts := strings .Split (string (out ), " " )
83+ if len (parts ) >= 3 {
84+ version = parts [2 ]
85+ } else {
86+ return "" , false , "Error parsing psql version output"
87+ }
88+ }
7389
7490 // Get the previously stored version
7591 oldVersion := versionCheck .GatherVersion ("postgres" )
@@ -79,6 +95,8 @@ func getPostgresVersionInfo() (string, bool, string) {
7995 }
8096
8197 if oldVersion != "" && oldVersion != version {
98+ versionCheck .CreateNews ("PostgreSQL" , oldVersion , version , false )
99+
82100 // Don't use fmt.Println for any output here
83101 return version , true , fmt .Sprintf ("Updated from %s to %s" , oldVersion , version )
84102 }
0 commit comments