Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: improve database SQL editor query latency by removing the ping from driver initializer (#2893)
Danny Xue7ca2dfa09b5
diff --git a/plugin/db/driver.go b/plugin/db/driver.goindex e973decfd6..cfb05f6097 100644--- a/plugin/db/driver.go+++ b/plugin/db/driver.go@@ -455,7 +455,7 @@ func Register(dbType Type, f driverFunc) {drivers[dbType] = f}-// Open opens a database specified by its database driver type and connection config.+// Open opens a database specified by its database driver type and connection config without verifying the connection.func Open(ctx context.Context, dbType Type, driverConfig DriverConfig, connectionConfig ConnectionConfig, connCtx ConnectionContext) (Driver, error) {driversMu.RLock()f, ok := drivers[dbType]@@ -469,11 +469,6 @@ func Open(ctx context.Context, dbType Type, driverConfig DriverConfig, connectioreturn nil, err}- if err := driver.Ping(ctx); err != nil {- _ = driver.Close(ctx)- return nil, err- }-return driver, nil}diff --git a/plugin/db/pg/pg.go b/plugin/db/pg/pg.goindex 3143732e16..f531995670 100644--- a/plugin/db/pg/pg.go+++ b/plugin/db/pg/pg.go@@ -114,6 +114,9 @@ func guessDSN(username, password, hostname, port, database, sslCA, sslCert, sslK"user": username,"password": password,}+ if database != "" {+ m["dbname"] = database+ }// We should use the default connection dsn without setting sslmode.// Some provider might still perform default SSL check at the server side so we@@ -135,22 +138,17 @@ func guessDSN(username, password, hostname, port, database, sslCA, sslCert, sslK}dsn := strings.Join(tokens, " ")- var guesses []stringif database != "" {- guesses = append(guesses, database)- } else {- // Guess default database postgres, template1.- guesses = append(guesses, "")- guesses = append(guesses, "bytebase")- guesses = append(guesses, "postgres")- guesses = append(guesses, "template1")+ return database, dsn, nil}+ // Guess default database postgres, template1.+ guesses := []string{"", "bytebase", "postgres", "template1"}// dsn+" dbname=bytebase"- for _, guess := range guesses {+ for _, guessDatabase := range guesses {guessDSN := dsn- if guess != "" {- guessDSN = fmt.Sprintf("%s dbname=%s", dsn, guess)+ if guessDatabase != "" {+ guessDSN = fmt.Sprintf("%s dbname=%s", dsn, guessDatabase)}if err := func() error {db, err := sql.Open(driverName, guessDSN)@@ -162,11 +160,7 @@ func guessDSN(username, password, hostname, port, database, sslCA, sslCert, sslK}(); err != nil {continue}- return guess, guessDSN, nil- }-- if database != "" {- return "", "", errors.Errorf("cannot connecting %q, make sure the connection info is correct and the database exists", database)+ return guessDatabase, guessDSN, nil}return "", "", errors.Errorf("cannot connecting instance, make sure the connection info is correct")}