diff --git a/hscontrol/db/db.go b/hscontrol/db/db.go index 030a6f0babd..828484d5188 100644 --- a/hscontrol/db/db.go +++ b/hscontrol/db/db.go @@ -12,13 +12,14 @@ import ( "github.com/glebarez/sqlite" "github.com/go-gormigrate/gormigrate/v2" - "github.com/juanfont/headscale/hscontrol/notifier" - "github.com/juanfont/headscale/hscontrol/types" - "github.com/juanfont/headscale/hscontrol/util" "github.com/rs/zerolog/log" "gorm.io/driver/postgres" "gorm.io/gorm" "gorm.io/gorm/logger" + + "github.com/juanfont/headscale/hscontrol/notifier" + "github.com/juanfont/headscale/hscontrol/types" + "github.com/juanfont/headscale/hscontrol/util" ) const ( @@ -360,10 +361,17 @@ func openDB(dbType, connectionAddr string, debug bool) (*gorm.DB, error) { return db, err case Postgres: - return gorm.Open(postgres.Open(connectionAddr), &gorm.Config{ + db, err := gorm.Open(postgres.Open(connectionAddr), &gorm.Config{ DisableForeignKeyConstraintWhenMigrating: true, Logger: dbLogger, }) + + sqlDB, _ := db.DB() + sqlDB.SetMaxOpenConns(10) + sqlDB.SetMaxIdleConns(10) + sqlDB.SetConnMaxIdleTime(time.Hour) + + return db, err } return nil, fmt.Errorf(