From f606e127f6d7b461628929face59c449bdaac6b3 Mon Sep 17 00:00:00 2001 From: Norwin Date: Fri, 29 Jul 2022 13:08:50 +0200 Subject: [PATCH 1/7] add SQLITE_JOURNAL_MODE setting to enable WAL --- custom/conf/app.example.ini | 1 + docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 + modules/setting/database.go | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 08708948940fa..6dc0e728f4a97 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -313,6 +313,7 @@ USER = root ;DB_TYPE = sqlite3 ;PATH= ; defaults to data/gitea.db ;SQLITE_TIMEOUT = ; Query timeout defaults to: 500 +;SQLITE_JOURNAL_MODE = ; defaults to DELETE, can be used to enable WAL mode. https://www.sqlite.org/pragma.html#pragma_journal_mode ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 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 31a294e1c9334..9a1c40dd0143d 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -382,6 +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. - `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 8fdd5f2bcb2ff..0b37826f282e4 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -39,6 +39,7 @@ var ( LogSQL bool Charset string Timeout int // seconds + SQliteJournalMode string UseSQLite3 bool UseMySQL bool UseMSSQL bool @@ -91,6 +92,8 @@ func InitDBConfig() { 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") + Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2) if Database.UseMySQL { Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFETIME").MustDuration(3 * time.Second) @@ -136,7 +139,8 @@ func DBConnStr() (string, error) { if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil { return "", fmt.Errorf("Failed to create directories: %v", err) } - connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate", Database.Path, Database.Timeout) + connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate&_journal_mode=%s", + Database.Path, Database.Timeout, Database.SQliteJournalMode) default: return "", fmt.Errorf("Unknown database type: %s", Database.Type) } From a6b84430584774e7f1eafbc1be934e2f6dc9f1aa Mon Sep 17 00:00:00 2001 From: Norwin Date: Sat, 30 Jul 2022 02:58:12 +0200 Subject: [PATCH 2/7] make default value OS dependent --- .../doc/advanced/config-cheat-sheet.en-us.md | 2 +- modules/setting/database.go | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) 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 9a1c40dd0143d..e94c4e6ea461f 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 0b37826f282e4..5b3a52845ed2e 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 { From 1f744f9e0a8efa2209489b5682046d13bd362fb8 Mon Sep 17 00:00:00 2001 From: Norwin Date: Sat, 30 Jul 2022 03:04:02 +0200 Subject: [PATCH 3/7] remove the setting, there are enough already --- custom/conf/app.example.ini | 1 - .../doc/advanced/config-cheat-sheet.en-us.md | 1 - modules/setting/database.go | 26 +++++++------------ 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 6dc0e728f4a97..08708948940fa 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -313,7 +313,6 @@ USER = root ;DB_TYPE = sqlite3 ;PATH= ; defaults to data/gitea.db ;SQLITE_TIMEOUT = ; Query timeout defaults to: 500 -;SQLITE_JOURNAL_MODE = ; defaults to DELETE, can be used to enable WAL mode. https://www.sqlite.org/pragma.html#pragma_journal_mode ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 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 e94c4e6ea461f..31a294e1c9334 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,6 @@ 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`: 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 5b3a52845ed2e..d462ab15328be 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -40,7 +40,6 @@ var ( LogSQL bool Charset string Timeout int // seconds - SQliteJournalMode string UseSQLite3 bool UseMySQL bool UseMSSQL bool @@ -90,24 +89,10 @@ func InitDBConfig() { if Database.UseMySQL && defaultCharset != "utf8mb4" { log.Error("Deprecated database mysql charset utf8 support, please use utf8mb4 or convert utf8 to utf8mb4.") } - 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 { Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFETIME").MustDuration(3 * time.Second) @@ -153,8 +138,17 @@ func DBConnStr() (string, error) { if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil { return "", fmt.Errorf("Failed to create directories: %v", err) } + + // 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: https://www.sqlite.org/wal.html + journalMode := "DELETE" + 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": + journalMode = "WAL" + } connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate&_journal_mode=%s", - Database.Path, Database.Timeout, Database.SQliteJournalMode) + Database.Path, Database.Timeout, journalMode) default: return "", fmt.Errorf("Unknown database type: %s", Database.Type) } From 195a2e98eac47d9651aff229a4931a77b4208911 Mon Sep 17 00:00:00 2001 From: Norwin Date: Sat, 30 Jul 2022 12:42:45 +0200 Subject: [PATCH 4/7] Revert "remove the setting, there are enough already" This reverts commit 1f744f9e0a8efa2209489b5682046d13bd362fb8. --- custom/conf/app.example.ini | 1 + .../doc/advanced/config-cheat-sheet.en-us.md | 1 + modules/setting/database.go | 26 ++++++++++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 08708948940fa..6dc0e728f4a97 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -313,6 +313,7 @@ USER = root ;DB_TYPE = sqlite3 ;PATH= ; defaults to data/gitea.db ;SQLITE_TIMEOUT = ; Query timeout defaults to: 500 +;SQLITE_JOURNAL_MODE = ; defaults to DELETE, can be used to enable WAL mode. https://www.sqlite.org/pragma.html#pragma_journal_mode ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 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 31a294e1c9334..e94c4e6ea461f 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -382,6 +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`: 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 d462ab15328be..5b3a52845ed2e 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -40,6 +40,7 @@ var ( LogSQL bool Charset string Timeout int // seconds + SQliteJournalMode string UseSQLite3 bool UseMySQL bool UseMSSQL bool @@ -89,10 +90,24 @@ func InitDBConfig() { if Database.UseMySQL && defaultCharset != "utf8mb4" { log.Error("Deprecated database mysql charset utf8 support, please use utf8mb4 or convert utf8 to utf8mb4.") } + 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 { Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFETIME").MustDuration(3 * time.Second) @@ -138,17 +153,8 @@ func DBConnStr() (string, error) { if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil { return "", fmt.Errorf("Failed to create directories: %v", err) } - - // 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: https://www.sqlite.org/wal.html - journalMode := "DELETE" - 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": - journalMode = "WAL" - } connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate&_journal_mode=%s", - Database.Path, Database.Timeout, journalMode) + Database.Path, Database.Timeout, Database.SQliteJournalMode) default: return "", fmt.Errorf("Unknown database type: %s", Database.Type) } From f7877607d9b2245185d3ebfb926c0b3f8a8b8fc4 Mon Sep 17 00:00:00 2001 From: Norwin Date: Sat, 30 Jul 2022 12:42:48 +0200 Subject: [PATCH 5/7] Revert "make default value OS dependent" This reverts commit a6b84430584774e7f1eafbc1be934e2f6dc9f1aa. --- .../doc/advanced/config-cheat-sheet.en-us.md | 2 +- modules/setting/database.go | 20 +++---------------- 2 files changed, 4 insertions(+), 18 deletions(-) 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 e94c4e6ea461f..9a1c40dd0143d 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`: 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. +- `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. - `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 5b3a52845ed2e..0b37826f282e4 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -11,7 +11,6 @@ import ( "os" "path" "path/filepath" - "runtime" "strings" "time" @@ -91,22 +90,9 @@ func InitDBConfig() { log.Error("Deprecated database mysql charset utf8 support, please use utf8mb4 or convert utf8 to utf8mb4.") } - 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.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") Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2) if Database.UseMySQL { From 406ca1accb0497bb95b5c16d769b971755561ec1 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sat, 30 Jul 2022 13:34:26 +0100 Subject: [PATCH 6/7] Do not set _journal_mode if `SQLITE_JOURNAL_MODE` is unset Signed-off-by: Andrew Thornton --- custom/conf/app.example.ini | 2 +- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 2 +- modules/setting/database.go | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 6dc0e728f4a97..1c6a7e3b7c61e 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -313,7 +313,7 @@ USER = root ;DB_TYPE = sqlite3 ;PATH= ; defaults to data/gitea.db ;SQLITE_TIMEOUT = ; Query timeout defaults to: 500 -;SQLITE_JOURNAL_MODE = ; defaults to DELETE, can be used to enable WAL mode. https://www.sqlite.org/pragma.html#pragma_journal_mode +;SQLITE_JOURNAL_MODE = ; defaults to sqlite database default (often DELETE), can be used to enable WAL mode. https://www.sqlite.org/pragma.html#pragma_journal_mode ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 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 9a1c40dd0143d..cb2b9526d7dbb 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`: **""**: 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. Defaults to the default for the database file, often DELETE. - `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 0b37826f282e4..6c241d4d2b501 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -92,7 +92,7 @@ func InitDBConfig() { 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") + Database.SQliteJournalMode = sec.Key("SQLITE_JOURNAL_MODE").MustString("") Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2) if Database.UseMySQL { @@ -139,8 +139,12 @@ func DBConnStr() (string, error) { if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil { return "", fmt.Errorf("Failed to create directories: %v", err) } - connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate&_journal_mode=%s", - Database.Path, Database.Timeout, Database.SQliteJournalMode) + journalMode := "" + if Database.SQliteJournalMode != "" { + journalMode = "&_journal_mode=" + Database.SQliteJournalMode + } + connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate%s", + Database.Path, Database.Timeout, journalMode) default: return "", fmt.Errorf("Unknown database type: %s", Database.Type) } From 00d4759a3a93fd9e91ecc07fa5ec5329c437650a Mon Sep 17 00:00:00 2001 From: Norwin Date: Sat, 30 Jul 2022 15:55:55 +0200 Subject: [PATCH 7/7] rename variable --- modules/setting/database.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/setting/database.go b/modules/setting/database.go index 6c241d4d2b501..af4e780d76bd4 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -39,7 +39,7 @@ var ( LogSQL bool Charset string Timeout int // seconds - SQliteJournalMode string + SQLiteJournalMode string UseSQLite3 bool UseMySQL bool UseMSSQL bool @@ -92,7 +92,7 @@ func InitDBConfig() { 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("") + Database.SQLiteJournalMode = sec.Key("SQLITE_JOURNAL_MODE").MustString("") Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2) if Database.UseMySQL { @@ -140,8 +140,8 @@ func DBConnStr() (string, error) { return "", fmt.Errorf("Failed to create directories: %v", err) } journalMode := "" - if Database.SQliteJournalMode != "" { - journalMode = "&_journal_mode=" + Database.SQliteJournalMode + if Database.SQLiteJournalMode != "" { + journalMode = "&_journal_mode=" + Database.SQLiteJournalMode } connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate%s", Database.Path, Database.Timeout, journalMode)