Skip to content

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

chore: start pg instance only when dataDir not existed (#2403)

boojackecb57cd022c1
diff --git a/server/instance.go b/server/instance.go
index 8ca557cd7b..0da01d2d4c 100644
--- a/server/instance.go
+++ b/server/instance.go
@@ -486,12 +486,15 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
port := 23333
dataDir := fmt.Sprintf("%s/%s", s.profile.DataDir, "tmp-pgdata")
- if err := postgres.InitDB(s.pgInstance.BaseDir, dataDir, pgUser); err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to init embedded postgres database").SetInternal(err)
- }
+ // If the data dir does not exist, then we will start a PostgreSQL instance with a fixed port temporarily.
+ if _, err := os.Stat(dataDir); os.IsNotExist(err) {
+ if err := postgres.InitDB(s.pgInstance.BaseDir, dataDir, pgUser); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to init embedded postgres database").SetInternal(err)
+ }
- if err := postgres.Start(port, s.pgInstance.BaseDir, dataDir, os.Stderr, os.Stderr); err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to start embedded postgres instance").SetInternal(err)
+ if err := postgres.Start(port, s.pgInstance.BaseDir, dataDir, os.Stderr, os.Stderr); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to start embedded postgres instance").SetInternal(err)
+ }
}
return c.JSON(http.StatusOK, pgConnectionInfo{