crowdsecurity/crowdsec · critical
unknown database type '%s'
Error message
unknown database type '%s'
What it means
ConnectionDialect maps the configured d.Type (mysql, sqlite, postgres, pgx, etc.) to a SQL dialect. If the type string does not match any known dialect it returns this error, which aborts NewClient before a database driver is ever opened. It is the strict validation guard against mistyped or unsupported database backends.
Source
Thrown at pkg/csconfig/database.go:235
return connString, nil
}
func (d *DatabaseCfg) ConnectionDialect() (string, string, error) {
switch d.Type {
case "sqlite":
return "sqlite3", dialect.SQLite, nil
case "mysql":
return "mysql", dialect.MySQL, nil
case "pgx", "postgresql", "postgres":
if d.Type != "pgx" {
log.Debugf("database type '%s' is deprecated, switching to 'pgx' instead", d.Type)
}
return "pgx", dialect.Postgres, nil
}
return "", "", fmt.Errorf("unknown database type '%s'", d.Type)
}
func (d *DatabaseCfg) isSocketConfig() bool {
return d.Host == "" && d.Port == 0 && d.DbPath != ""
}
View on GitHub (pinned to 909b515798)
Solutions
- Set database.type to one of the supported values: mysql, sqlite, postgres, postgresql, or pgx.
- For MariaDB, use type: mysql — the MySQL driver speaks the MariaDB wire protocol.
- For PostgreSQL, prefer type: pgx (postgres/postgresql map to pgx anyway).
- Check for trailing whitespace or wrong indentation in database.yaml that could corrupt the type value.
Example fix
// before (database.yaml) database: type: psql // after database: type: pgx
Defensive patterns
Strategy: validation
Validate before calling
var supported = []string{"mysql", "sqlite", "postgres", "postgresql", "pgx"}
if !slices.Contains(supported, strings.TrimSpace(dbCfg.Type)) {
return fmt.Errorf("database.type %q not in %v", dbCfg.Type, supported)
} Try / catch
if _, err := dbCfg.ConnectionDialect(); err != nil {
log.Fatalf("invalid database config: %v", err) // fail fast with clear message
} Prevention
- Never hand-edit database.type; copy from the upstream example config.
- Remember mariadb must be declared as mysql and postgres should be pgx.
- Add a config lint step (yamllint + custom schema check) to deployment pipelines.
When it happens
Trigger: database.type in the config yaml is set to anything other than mysql, sqlite, postgres, postgresql, or pgx — e.g. type: mysqlb, type: psql, or type: mariadb.
Common situations: Typos in database.yaml after editing, copy-pasted configs from other tools (e.g. 'psql'), or configs written for a hypothetical backend (mariadb) that crowdsec does not declare as a type.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- path must start with /
- basic_auth is selected, but basic_auth is not provided
- basic_auth is selected, but username is not provided
- basic_auth is selected, but password is not provided
- headers is selected, but headers is not provided
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/083c1c74b552f772.
Report an issue: GitHub.