{"record":{"id":"ff3dee6f38c0b662","repo":"crowdsecurity/crowdsec","slug":"no-database-configuration-provided","errorCode":null,"errorMessage":"no database configuration provided","messagePattern":"no database configuration provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/csconfig/database.go","lineNumber":74,"sourceCode":"\tCertDuration          *time.Duration\n\tApi                   *string `yaml:\"api_key,omitempty\"`\n\tApiDuration           *time.Duration\n\tLoginPassword         *string `yaml:\"login_password,omitempty\"`\n\tLoginPasswordDuration *time.Duration\n}\n\ntype FlushDBCfg struct {\n\tMaxItems *int `yaml:\"max_items,omitempty\"`\n\t// We could unmarshal as time.Duration, but alert filters right now are a map of strings\n\tMaxAge        cstime.DurationWithDays `yaml:\"max_age,omitempty\"`\n\tBouncersGC    *AuthGCCfg              `yaml:\"bouncers_autodelete,omitempty\"`\n\tAgentsGC      *AuthGCCfg              `yaml:\"agents_autodelete,omitempty\"`\n\tMetricsMaxAge cstime.DurationWithDays `yaml:\"metrics_max_age,omitempty\"`\n}\n\nfunc (c *Config) LoadDBConfig(inCli bool) error {\n\tif c.DbConfig == nil {\n\t\treturn errors.New(\"no database configuration provided\")\n\t}\n\n\tif c.Cscli != nil {\n\t\tc.Cscli.DbConfig = c.DbConfig\n\t}\n\n\tif c.API != nil && c.API.Server != nil {\n\t\tc.API.Server.DbConfig = c.DbConfig\n\t}\n\n\tif c.DbConfig.MaxOpenConns == 0 {\n\t\tc.DbConfig.MaxOpenConns = DEFAULT_MAX_OPEN_CONNS\n\t}\n\n\tif !inCli && c.DbConfig.Type == \"sqlite\" {\n\t\tif c.DbConfig.UseWal == nil {\n\t\t\tdbDir := filepath.Dir(c.DbConfig.DbPath)\n\t\t\tisNetwork, fsType, err := fsutil.IsNetworkFS(dbDir)","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/csconfig/database.go#L56-L92","documentation":"LoadDBConfig requires a decoded DbConfig (the 'db_config' section). When DbConfig is nil there is no database to connect to and shared config propagation (to cscli and API server) cannot proceed, so the error is raised before any defaults are applied.","triggerScenarios":"Calling Config.LoadDBConfig when the YAML had no 'db_config:' section; calling it before the config file has been parsed; API server startup (LoadAPIServer) on a config stripped of db_config.","commonSituations":"Minimal LAPI config missing db_config; tests building Config structs manually; users commenting out db_config while debugging and forgetting to restore it.","solutions":["Add a db_config section to the config file, e.g. db_config: {log_level: info, type: sqlite3, db_path: /var/lib/crowdsec/data/crowdsec.db}","Ensure NewConfig parsed the file into cfg.DbConfig before LoadDBConfig is invoked","For cscli-only usage, still provide db_config so the CLI can reach the same database"],"exampleFix":"// before\napi:\n  server:\n    enabled: true\n\n// after\ndb_config:\n  type: sqlite3\n  db_path: /var/lib/crowdsec/data/crowdsec.db\napi:\n  server:\n    enabled: true","handlingStrategy":"validation","validationCode":"if cfg.DbConfig == nil {\n    return fmt.Errorf(\"config file must contain a 'db_config' section\")\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.LoadDBConfig(false); err != nil {\n    if strings.Contains(err.Error(), \"no database configuration\") {\n        log.Fatal(\"add a db_config section to the config file\")\n    }\n    return err\n}","preventionTips":["Keep db_config in every environment's config, even cscli-only hosts","Load config via csconfig.NewConfig so DbConfig is decoded before LoadDBConfig","Lint config files in CI with a smoke NewConfig+LoadDBConfig call"],"tags":["config","database","crowdsec"],"backgroundTag":"missing-required-config-field","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}