Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: neon connection and external pg url when port is not specified (#6363)

Tianzhou (天舟)285c6552b90b
diff --git a/backend/plugin/db/pg/pg.go b/backend/plugin/db/pg/pg.go
index c8e774cf35..91f58752cd 100644
--- a/backend/plugin/db/pg/pg.go
+++ b/backend/plugin/db/pg/pg.go
@@ -82,12 +82,27 @@ func (driver *Driver) Open(_ context.Context, _ db.Type, config db.ConnectionCon
return nil, errors.Errorf("user must be set")
}
+ if config.Host == "" {
+ return nil, errors.Errorf("host must be set")
+ }
+
+ if config.Port == "" {
+ return nil, errors.Errorf("port must be set")
+ }
+
if (config.TLSConfig.SslCert == "" && config.TLSConfig.SslKey != "") ||
(config.TLSConfig.SslCert != "" && config.TLSConfig.SslKey == "") {
return nil, errors.Errorf("ssl-cert and ssl-key must be both set or unset")
}
- connConfig, err := pgx.ParseConfig(fmt.Sprintf("host=%s port=%s", config.Host, config.Port))
+ connStr := fmt.Sprintf("host=%s port=%s", config.Host, config.Port)
+ // Neon requires new driver, however due to https://github.com/jackc/pgx/issues/1600, we have to
+ // stay at pgx/v4 to support SSH tunnelling. So we do a hack here to support Neon SSL following
+ // https://neon.tech/docs/connect/connectivity-issues#c-set-verify-full-for-golang-based-clients
+ if strings.HasSuffix(config.Host, ".neon.tech") {
+ connStr += " sslmode=verify-full"
+ }
+ connConfig, err := pgx.ParseConfig(connStr)
if err != nil {
return nil, err
}
diff --git a/backend/store/metadb.go b/backend/store/metadb.go
index 814a85485c..e8a8bd576c 100644
--- a/backend/store/metadb.go
+++ b/backend/store/metadb.go
@@ -137,6 +137,10 @@ func (m *MetadataDB) connectExternal(readonly bool, version string) (*DB, error)
connCfg.Port = port
}
+ if connCfg.Port == "" {
+ connCfg.Port = "5432"
+ }
+
if u.Path == "" {
return nil, errors.Errorf("missing database in the --pg connection string")
}