Manager: limit database connections

Limit the database connection pool to only a single connection. I hope that
this will solve the intermittent `SQLITE_BUSY` errors I've been seeing.
This commit is contained in:
Sybren A. Stüvel 2022-05-12 13:58:15 +02:00
parent 4bdaeb73a6
commit d35ca9d98f

View File

@ -62,6 +62,16 @@ func openDBWithConfig(dsn string, config *gorm.Config) (*DB, error) {
return nil, err
}
// Use the generic sql.DB interface to set some connection pool options.
sqlDB, err := gormDB.DB()
if err != nil {
return nil, err
}
// Only allow a single database connection, to avoid SQLITE_BUSY errors.
// It's not certain that this'll improve the situation, but it's worth a try.
sqlDB.SetMaxIdleConns(1) // Max num of connections in the idle connection pool.
sqlDB.SetMaxOpenConns(1) // Max num of open connections to the database.
db := DB{
gormDB: gormDB,
}