Skip to content

Commit de5dc97

Browse files
jasonishabonander
authored andcommitted
fix: sqlite pragma order for auto_vacuum (launchbadge#3230)
* 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]>
1 parent 9e9575b commit de5dc97

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

sqlx-sqlite/src/options/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ impl SqliteConnectOptions {
162162
// https://www.sqlite.org/wal.html#use_of_wal_without_shared_memory
163163
pragmas.insert("locking_mode".into(), None);
164164

165+
// `auto_vacuum` needs to be executed before `journal_mode`, if set.
166+
//
167+
// Otherwise, a change in the `journal_mode` setting appears to mark even an empty database as dirty,
168+
// requiring a `vacuum` command to be executed to actually apply the new `auto_vacuum` setting.
169+
pragmas.insert("auto_vacuum".into(), None);
170+
165171
// Don't set `journal_mode` unless the user requested it.
166172
// WAL mode is a permanent setting for created databases and changing into or out of it
167173
// requires an exclusive lock that can't be waited on with `sqlite3_busy_timeout()`.
@@ -176,8 +182,6 @@ impl SqliteConnectOptions {
176182
// https://www.sqlite.org/compile.html#default_synchronous.
177183
pragmas.insert("synchronous".into(), None);
178184

179-
pragmas.insert("auto_vacuum".into(), None);
180-
181185
// Soft limit on the number of rows that `ANALYZE` touches per index.
182186
pragmas.insert("analysis_limit".into(), None);
183187

0 commit comments

Comments
 (0)