Skip to content

Commit

Permalink
fix: sqlite pragma order for auto_vacuum (#3230)
Browse files Browse the repository at this point in the history
* fix: sqlite pragma order for auto_vacuum

Setting the auto_vacuum pragma must come before setting the journal
mode otherwise it won't apply.

* fix: better documentation for auto_vacuum

Co-authored-by: Austin Bonander <[email protected]>

---------

Co-authored-by: Austin Bonander <[email protected]>
  • Loading branch information
jasonish and abonander authored May 18, 2024
1 parent e7f7190 commit 0449ac5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sqlx-sqlite/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ impl SqliteConnectOptions {
// https://www.sqlite.org/wal.html#use_of_wal_without_shared_memory
pragmas.insert("locking_mode".into(), None);

// `auto_vacuum` needs to be executed before `journal_mode`, if set.
//
// Otherwise, a change in the `journal_mode` setting appears to mark even an empty database as dirty,
// requiring a `vacuum` command to be executed to actually apply the new `auto_vacuum` setting.
pragmas.insert("auto_vacuum".into(), None);

// Don't set `journal_mode` unless the user requested it.
// WAL mode is a permanent setting for created databases and changing into or out of it
// requires an exclusive lock that can't be waited on with `sqlite3_busy_timeout()`.
Expand All @@ -176,8 +182,6 @@ impl SqliteConnectOptions {
// https://www.sqlite.org/compile.html#default_synchronous.
pragmas.insert("synchronous".into(), None);

pragmas.insert("auto_vacuum".into(), None);

// Soft limit on the number of rows that `ANALYZE` touches per index.
pragmas.insert("analysis_limit".into(), None);

Expand Down

0 comments on commit 0449ac5

Please sign in to comment.