diff --git a/management/server/store/sql_store.go b/management/server/store/sql_store.go index b5f4d8cbf..1e698d2ae 100644 --- a/management/server/store/sql_store.go +++ b/management/server/store/sql_store.go @@ -49,6 +49,11 @@ const ( accountAndIDsQueryCondition = "account_id = ? AND id IN ?" accountIDCondition = "account_id = ?" peerNotFoundFMT = "peer %s not found" + + pgMaxConnections = 30 + pgMinConnections = 5 + pgMaxConnLifetime = 60 * time.Minute + pgHealthCheckPeriod = 1 * time.Minute ) // SqlStore represents an account storage backed by a Sql DB persisted to disk @@ -2101,10 +2106,10 @@ func connectToPgDb(ctx context.Context, dsn string) (*pgxpool.Pool, error) { return nil, fmt.Errorf("unable to parse database config: %w", err) } - config.MaxConns = 10 - config.MinConns = 2 - config.MaxConnLifetime = time.Hour - config.HealthCheckPeriod = time.Minute + config.MaxConns = pgMaxConnections + config.MinConns = pgMinConnections + config.MaxConnLifetime = pgMaxConnLifetime + config.HealthCheckPeriod = pgHealthCheckPeriod pool, err := pgxpool.NewWithConfig(ctx, config) if err != nil { @@ -2116,7 +2121,6 @@ func connectToPgDb(ctx context.Context, dsn string) (*pgxpool.Pool, error) { return nil, fmt.Errorf("unable to ping database: %w", err) } - fmt.Println("Successfully connected to the database!") return pool, nil } diff --git a/management/server/store/sqlstore_bench_test.go b/management/server/store/sqlstore_bench_test.go index b131c69ac..74bdb83b4 100644 --- a/management/server/store/sqlstore_bench_test.go +++ b/management/server/store/sqlstore_bench_test.go @@ -42,7 +42,7 @@ func (s *SqlStore) GetAccountSlow(ctx context.Context, accountID string) (*types var account types.Account result := s.db.Model(&account). Omit("GroupsG"). - Preload("UsersG.PATsG"). // have to be specifies as this is nester reference + Preload("UsersG.PATsG"). // have to be specified as this is nested reference Preload(clause.Associations). Take(&account, idQueryCondition, accountID) if result.Error != nil {