mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-13 18:10:25 +02:00
kvdb/sqlite: enable incremental auto_vacuum on DB creation
In this commit, we make a change that enables the `auto_vacuum = incremental` pragma for SQLite databases, but only when the database file is first created. Incremental auto-vacuum allows SQLite to reclaim unused space within the database file over time, preventing indefinite growth.
This commit is contained in:
@@ -24,6 +24,12 @@ const (
|
|||||||
sqliteTxLockImmediate = "_txlock=immediate"
|
sqliteTxLockImmediate = "_txlock=immediate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// pragmaOption holds a key-value pair for a SQLite pragma setting.
|
||||||
|
type pragmaOption struct {
|
||||||
|
name string
|
||||||
|
value string
|
||||||
|
}
|
||||||
|
|
||||||
// NewSqliteBackend returns a db object initialized with the passed backend
|
// NewSqliteBackend returns a db object initialized with the passed backend
|
||||||
// config. If a sqlite connection cannot be established, then an error is
|
// config. If a sqlite connection cannot be established, then an error is
|
||||||
// returned.
|
// returned.
|
||||||
@@ -31,10 +37,7 @@ func NewSqliteBackend(ctx context.Context, cfg *Config, dbPath, fileName,
|
|||||||
prefix string) (walletdb.DB, error) {
|
prefix string) (walletdb.DB, error) {
|
||||||
|
|
||||||
// First, we add a set of mandatory pragma options to the query.
|
// First, we add a set of mandatory pragma options to the query.
|
||||||
pragmaOptions := []struct {
|
pragmaOptions := []pragmaOption{
|
||||||
name string
|
|
||||||
value string
|
|
||||||
}{
|
|
||||||
{
|
{
|
||||||
name: "busy_timeout",
|
name: "busy_timeout",
|
||||||
value: fmt.Sprintf(
|
value: fmt.Sprintf(
|
||||||
@@ -49,7 +52,12 @@ func NewSqliteBackend(ctx context.Context, cfg *Config, dbPath, fileName,
|
|||||||
name: "journal_mode",
|
name: "journal_mode",
|
||||||
value: "WAL",
|
value: "WAL",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "auto_vacuum",
|
||||||
|
value: "incremental",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
sqliteOptions := make(url.Values)
|
sqliteOptions := make(url.Values)
|
||||||
for _, option := range pragmaOptions {
|
for _, option := range pragmaOptions {
|
||||||
sqliteOptions.Add(
|
sqliteOptions.Add(
|
||||||
|
Reference in New Issue
Block a user