Compare commits

...

2 commits

Author SHA1 Message Date
Kristoffer Dalby
f0424585a3
Merge 716d86f71e into 6275399327 2024-11-18 08:25:54 +01:00
Kristoffer Dalby
716d86f71e
make configurable wal auto checkpoint
SQLite WAL addition disabled auto checkpoint, this
makes the WAL grow forever, not sure why I did that.

Make it configurable, set it to SQLite default.

Fixes #2204

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
2024-11-17 14:31:25 -07:00
3 changed files with 14 additions and 6 deletions

View file

@ -168,6 +168,11 @@ database:
# https://www.sqlite.org/wal.html
write_ahead_log: true
# Maximum number of WAL file frames before the WAL file is automatically checkpointed.
# https://www.sqlite.org/c3ref/wal_autocheckpoint.html
# Set to 0 to disable automatic checkpointing.
wal_autocheckpoint: 1000
# # Postgres config
# Please note that using Postgres is highly discouraged as it is only supported for legacy reasons.
# See database.type for more information.

View file

@ -543,10 +543,10 @@ func openDB(cfg types.DatabaseConfig) (*gorm.DB, error) {
}
if cfg.Sqlite.WriteAheadLog {
if err := db.Exec(`
if err := db.Exec(fmt.Sprintf(`
PRAGMA journal_mode=WAL;
PRAGMA wal_autocheckpoint=0;
`).Error; err != nil {
PRAGMA wal_autocheckpoint=%d;
`, cfg.Sqlite.WALAutoCheckPoint)).Error; err != nil {
return nil, fmt.Errorf("setting WAL mode: %w", err)
}
}

View file

@ -104,6 +104,7 @@ type Nameservers struct {
type SqliteConfig struct {
Path string
WriteAheadLog bool
WALAutoCheckPoint int
}
type PostgresConfig struct {
@ -270,6 +271,7 @@ func LoadConfig(path string, isFile bool) error {
viper.SetDefault("database.postgres.conn_max_idle_time_secs", 3600)
viper.SetDefault("database.sqlite.write_ahead_log", true)
viper.SetDefault("database.sqlite.wal_autocheckpoint", 1000) // SQLite default
viper.SetDefault("oidc.scope", []string{oidc.ScopeOpenID, "profile", "email"})
viper.SetDefault("oidc.only_start_if_oidc_is_available", true)
@ -543,6 +545,7 @@ func databaseConfig() DatabaseConfig {
viper.GetString("database.sqlite.path"),
),
WriteAheadLog: viper.GetBool("database.sqlite.write_ahead_log"),
WALAutoCheckPoint: viper.GetInt("database.sqlite.wal_autocheckpoint"),
},
Postgres: PostgresConfig{
Host: viper.GetString("database.postgres.host"),