@@ -27,6 +27,20 @@ const (
2727 availableDBsTemplate = `select datname from pg_catalog.pg_database
2828 where not datistemplate and has_database_privilege('%s', datname, 'CONNECT')`
2929
30+ dbVersionQuery = `select setting::integer/10000 from pg_settings where name = 'server_version_num'`
31+
32+ tuningParamsQuery = `select
33+ name, setting
34+ from
35+ pg_settings
36+ where
37+ source <> 'default'
38+ and (
39+ name ~ '(work_mem$|^enable_|_cost$|scan_size$|effective_cache_size|^jit)'
40+ or name ~ '(^geqo|default_statistics_target|constraint_exclusion|cursor_tuple_fraction)'
41+ or name ~ '(collapse_limit$|parallel|plan_cache_mode)'
42+ )`
43+
3044 // maxNumberVerifiedDBs defines the maximum number of databases to verify availability as a database source.
3145 // The DB source instance can contain a large number of databases, so the verification will take a long time.
3246 // Therefore, we introduced a limit on the maximum number of databases to check for suitability as a source.
@@ -50,6 +64,11 @@ type locale struct {
5064 ctype string
5165}
5266
67+ type tuningParam struct {
68+ name string
69+ setting string
70+ }
71+
5372// ConnectionString builds PostgreSQL connection string.
5473func ConnectionString (host , port , username , dbname , password string ) string {
5574 return fmt .Sprintf ("host=%s port=%s user='%s' database='%s' password='%s'" , host , port , username , dbname , password )
@@ -114,10 +133,22 @@ func CheckSource(ctx context.Context, conf *models.ConnectionTest, imageContent
114133 return tcResponse , nil
115134 }
116135
136+ dbVersion , err := getMajorVersion (ctx , conn )
137+ if err != nil {
138+ return nil , err
139+ }
140+
141+ tuningParameters , err := getTuningParameters (ctx , conn )
142+ if err != nil {
143+ return nil , err
144+ }
145+
117146 return & models.TestConnection {
118- Status : models .TCStatusOK ,
119- Result : models .TCResultOK ,
120- Message : models .TCMessageOK ,
147+ Status : models .TCStatusOK ,
148+ Result : models .TCResultOK ,
149+ Message : models .TCMessageOK ,
150+ DBVersion : dbVersion ,
151+ TuningParams : tuningParameters ,
121152 }, nil
122153}
123154
@@ -352,3 +383,36 @@ func buildLocalesWarningMessage(dbName string, missingLocales []locale) string {
352383
353384 return sb .String ()
354385}
386+
387+ func getMajorVersion (ctx context.Context , conn * pgx.Conn ) (int , error ) {
388+ var majorVersion int
389+
390+ row := conn .QueryRow (ctx , dbVersionQuery )
391+
392+ if err := row .Scan (& majorVersion ); err != nil {
393+ return 0 , fmt .Errorf ("failed to perform query detecting major version: %w" , err )
394+ }
395+
396+ return majorVersion , nil
397+ }
398+
399+ func getTuningParameters (ctx context.Context , conn * pgx.Conn ) (map [string ]string , error ) {
400+ rows , err := conn .Query (ctx , tuningParamsQuery )
401+ if err != nil {
402+ return nil , fmt .Errorf ("failed to perform query detecting query tuning params: %w" , err )
403+ }
404+
405+ var tuningParams = make (map [string ]string )
406+
407+ for rows .Next () {
408+ var param tuningParam
409+
410+ if err := rows .Scan (& param .name , & param .setting ); err != nil {
411+ return nil , fmt .Errorf ("failed to scan query tuning params: %w" , err )
412+ }
413+
414+ tuningParams [param .name ] = param .setting
415+ }
416+
417+ return tuningParams , nil
418+ }
0 commit comments