@@ -27,6 +27,20 @@ const (
27
27
availableDBsTemplate = `select datname from pg_catalog.pg_database
28
28
where not datistemplate and has_database_privilege('%s', datname, 'CONNECT')`
29
29
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
+
30
44
// maxNumberVerifiedDBs defines the maximum number of databases to verify availability as a database source.
31
45
// The DB source instance can contain a large number of databases, so the verification will take a long time.
32
46
// 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 {
50
64
ctype string
51
65
}
52
66
67
+ type tuningParam struct {
68
+ name string
69
+ setting string
70
+ }
71
+
53
72
// ConnectionString builds PostgreSQL connection string.
54
73
func ConnectionString (host , port , username , dbname , password string ) string {
55
74
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
114
133
return tcResponse , nil
115
134
}
116
135
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
+
117
146
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 ,
121
152
}, nil
122
153
}
123
154
@@ -352,3 +383,36 @@ func buildLocalesWarningMessage(dbName string, missingLocales []locale) string {
352
383
353
384
return sb .String ()
354
385
}
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