1 parent
9ceeb3bd65
commit
4ae5003763
4 files changed
+21
-5
No files matched your search
@@ -88,8 +88,9 @@ type Server struct {
|
||||
DevTargetSessionMaxSeconds int
|
||||
DevTargetSessionConnectionLimit int
|
||||
|
||||
DatabaseUrl string
|
||||
DevDatabaseCleanupFunc func() error
|
||||
DatabaseUrl string
|
||||
DatabaseMaxOpenConnections int
|
||||
DevDatabaseCleanupFunc func() error
|
||||
|
||||
Database *gorm.DB
|
||||
}
|
||||
@@ -453,7 +454,11 @@ func (b *Server) ConnectToDatabase(dialect string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create db object with dialect %s: %w", dialect, err)
|
||||
}
|
||||
|
||||
if b.DatabaseMaxOpenConnections == 1 {
|
||||
return fmt.Errorf("unable to create db object with dialect %s: %s", dialect, "max_open_connections must be unlimited by setting 0 or at least 2")
|
||||
} else {
|
||||
dbase.DB().SetMaxOpenConns(b.DatabaseMaxOpenConnections)
|
||||
}
|
||||
b.Database = dbase
|
||||
if os.Getenv("BOUNDARY_DISABLE_GORM_FORMATTER") == "" {
|
||||
gorm.LogFormatter = db.GetGormLogFormatter(b.Logger)
|
||||
|
||||
@@ -366,6 +366,8 @@ func (c *Command) Run(args []string) int {
|
||||
c.UI.Error(fmt.Errorf("Error parsing database url: %w", err).Error())
|
||||
return base.CommandUserError
|
||||
}
|
||||
c.DatabaseMaxOpenConnections = c.Config.Controller.Database.MaxOpenConnections
|
||||
|
||||
if err := c.ConnectToDatabase("postgres"); err != nil {
|
||||
c.UI.Error(fmt.Errorf("Error connecting to database: %w", err).Error())
|
||||
return base.CommandCliError
|
||||
|
||||
@@ -133,8 +133,9 @@ type Worker struct {
|
||||
}
|
||||
|
||||
type Database struct {
|
||||
Url string `hcl:"url"`
|
||||
MigrationUrl string `hcl:"migration_url"`
|
||||
Url string `hcl:"url"`
|
||||
MigrationUrl string `hcl:"migration_url"`
|
||||
MaxOpenConnections int `hcl:"max_open_connections"`
|
||||
}
|
||||
|
||||
// DevWorker is a Config that is used for dev mode of Boundary
|
||||
|
||||
@@ -15,6 +15,7 @@ controller {
|
||||
description = "An example controller"
|
||||
database {
|
||||
url = "postgresql://<username>:<password>@10.0.0.1:5432/<database_name>"
|
||||
max_open_connections = 2
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -28,6 +29,13 @@ controller {
|
||||
- `url` - Configures the URL for connecting to Postgres
|
||||
- `migration_url` - Can be used to specify a different URL for migrations, as that
|
||||
usually requires higher privileges.
|
||||
- `max_open_connections` - Can be used to control the maximum number of
|
||||
connections that can be opened by the controller. The minimum number of
|
||||
connections required is 2. Every controller requires 1 non-pooled
|
||||
shared lock connection (which is held for the lifetime of the controller) and
|
||||
a minimum of 1 pooled connection which is used for all other database
|
||||
requests. Setting this value to 0 will allow the controller to open as many
|
||||
connections as needed.
|
||||
|
||||
Either can refer to a file on disk (file://) from which a URL will be read; an env
|
||||
var (env://) from which the URL will be read; or a direct database URL (postgres://).
|
||||
|
||||
Reference in new issue
Block a user