diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 9a1c40dd0143..e94c4e6ea461 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -382,7 +382,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a - `verify-ca`: Enable TLS with verification of the database server certificate against its root certificate. - `verify-full`: Enable TLS and verify the database server name matches the given certificate in either the `Common Name` or `Subject Alternative Name` fields. - `SQLITE_TIMEOUT`: **500**: Query timeout for SQLite3 only. -- `SQLITE_JOURNAL_MODE`: **DELETE**: Change journal mode for SQlite3. Can be used to enable [WAL mode](https://www.sqlite.org/wal.html) when high load causes write congestion. See [SQlite3 docs](https://www.sqlite.org/pragma.html#pragma_journal_mode) for possible values. +- `SQLITE_JOURNAL_MODE`: on windows & linux: **WAL**, otherwise **DELETE**: Change journal mode for SQlite3. See [SQlite3 docs](https://www.sqlite.org/pragma.html#pragma_journal_mode) for possible values. - `ITERATE_BUFFER_SIZE`: **50**: Internal buffer size for iterating. - `CHARSET`: **utf8mb4**: For MySQL only, either "utf8" or "utf8mb4". NOTICE: for "utf8mb4" you must use MySQL InnoDB > 5.6. Gitea is unable to check this. - `PATH`: **data/gitea.db**: For SQLite3 only, the database file path. diff --git a/modules/setting/database.go b/modules/setting/database.go index 0b37826f282e..5b3a52845ed2 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -11,6 +11,7 @@ import ( "os" "path" "path/filepath" + "runtime" "strings" "time" @@ -90,9 +91,22 @@ func InitDBConfig() { log.Error("Deprecated database mysql charset utf8 support, please use utf8mb4 or convert utf8 to utf8mb4.") } - Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db")) - Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500) - Database.SQliteJournalMode = sec.Key("SQLITE_JOURNAL_MODE").MustString("DELETE") + if Database.UseSQLite3 { + Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db")) + Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500) + + // WAL mode is preferred for better concurent write performance, but needs special VFS driver features, + // which are guaranteed to be available for unix & windows OSes + var defaultJournalMode string + switch runtime.GOOS { + // probably the BSDs are supported too, but i found no information on this - better safe than sorry. + case "windows", "linux": // "darwin", "freebsd", "openbsd", "netbsd": + defaultJournalMode = "WAL" + default: + defaultJournalMode = "DELETE" + } + Database.SQliteJournalMode = sec.Key("SQLITE_JOURNAL_MODE").MustString(defaultJournalMode) + } Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2) if Database.UseMySQL {