mirror of
https://github.com/go-gitea/gitea
synced 2024-11-25 23:02:52 +01:00
Add setting SQLITE_JOURNAL_MODE
to enable WAL (#20535)
Co-authored-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
ae3dde1c87
commit
8a330b6b5b
3 changed files with 11 additions and 1 deletions
|
@ -313,6 +313,7 @@ USER = root
|
||||||
;DB_TYPE = sqlite3
|
;DB_TYPE = sqlite3
|
||||||
;PATH= ; defaults to data/gitea.db
|
;PATH= ; defaults to data/gitea.db
|
||||||
;SQLITE_TIMEOUT = ; Query timeout defaults to: 500
|
;SQLITE_TIMEOUT = ; Query timeout defaults to: 500
|
||||||
|
;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
|
||||||
;;
|
;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -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-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.
|
- `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_TIMEOUT`: **500**: Query timeout for SQLite3 only.
|
||||||
|
- `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.
|
- `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.
|
- `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.
|
- `PATH`: **data/gitea.db**: For SQLite3 only, the database file path.
|
||||||
|
|
|
@ -39,6 +39,7 @@ var (
|
||||||
LogSQL bool
|
LogSQL bool
|
||||||
Charset string
|
Charset string
|
||||||
Timeout int // seconds
|
Timeout int // seconds
|
||||||
|
SQLiteJournalMode string
|
||||||
UseSQLite3 bool
|
UseSQLite3 bool
|
||||||
UseMySQL bool
|
UseMySQL bool
|
||||||
UseMSSQL bool
|
UseMSSQL bool
|
||||||
|
@ -91,6 +92,8 @@ func InitDBConfig() {
|
||||||
|
|
||||||
Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
|
Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
|
||||||
Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
|
Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
|
||||||
|
Database.SQLiteJournalMode = sec.Key("SQLITE_JOURNAL_MODE").MustString("")
|
||||||
|
|
||||||
Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2)
|
Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2)
|
||||||
if Database.UseMySQL {
|
if Database.UseMySQL {
|
||||||
Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFETIME").MustDuration(3 * time.Second)
|
Database.ConnMaxLifetime = sec.Key("CONN_MAX_LIFETIME").MustDuration(3 * time.Second)
|
||||||
|
@ -136,7 +139,12 @@ func DBConnStr() (string, error) {
|
||||||
if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil {
|
if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil {
|
||||||
return "", fmt.Errorf("Failed to create directories: %v", err)
|
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)
|
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:
|
default:
|
||||||
return "", fmt.Errorf("Unknown database type: %s", Database.Type)
|
return "", fmt.Errorf("Unknown database type: %s", Database.Type)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue