diff --git a/pkg/csconfig/database.go b/pkg/csconfig/database.go index b2fd18d7d..aa3e3ce97 100644 --- a/pkg/csconfig/database.go +++ b/pkg/csconfig/database.go @@ -22,6 +22,7 @@ type DatabaseCfg struct { Flush *FlushDBCfg `yaml:"flush"` LogLevel *log.Level `yaml:"log_level"` MaxOpenConns *int `yaml:"max_open_conns,omitempty"` + UseWal *bool `yaml:"use_wal,omitempty"` } type AuthGCCfg struct { diff --git a/pkg/database/database.go b/pkg/database/database.go index 08f183630..b22075704 100644 --- a/pkg/database/database.go +++ b/pkg/database/database.go @@ -76,7 +76,16 @@ func NewClient(config *csconfig.DatabaseCfg) (*Client, error) { return &Client{}, fmt.Errorf("unable to set perms on %s: %v", config.DbPath, err) } } - drv, err := getEntDriver("sqlite3", dialect.SQLite, fmt.Sprintf("file:%s?_busy_timeout=100000&_fk=1", config.DbPath), config) + if config.UseWal == nil { + entLogger.Warn("you are using sqlite without WAL, this can have an impact of performance. If you do not store the database in a network share, set db_config.use_wal to true. Set explicitly to false to disable this warning.") + } + var sqliteConnectionStringParameters string + if config.UseWal != nil && *config.UseWal { + sqliteConnectionStringParameters = "_busy_timeout=100000&_fk=1&_journal_mode=WAL" + } else { + sqliteConnectionStringParameters = "_busy_timeout=100000&_fk=1" + } + drv, err := getEntDriver("sqlite3", dialect.SQLite, fmt.Sprintf("file:%s?%s", config.DbPath, sqliteConnectionStringParameters), config) if err != nil { return &Client{}, errors.Wrapf(err, "failed opening connection to sqlite: %v", config.DbPath) } diff --git a/tests/lib/config/config-local b/tests/lib/config/config-local index 9b63c285d..7c83df8c0 100755 --- a/tests/lib/config/config-local +++ b/tests/lib/config/config-local @@ -81,6 +81,7 @@ config_generate() { .config_paths.plugin_dir=strenv(PLUGIN_DIR) | .crowdsec_service.acquisition_path=strenv(CONFIG_DIR)+"/acquis.yaml" | .db_config.db_path=strenv(DATA_DIR)+"/crowdsec.db" | + .db_config.use_wal=true | .api.client.credentials_path=strenv(CONFIG_DIR)+"/local_api_credentials.yaml" | .api.server.profiles_path=strenv(CONFIG_DIR)+"/profiles.yaml" | .api.server.console_path=strenv(CONFIG_DIR)+"/console.yaml" |