File tree Expand file tree Collapse file tree
crates/sqlx-sqlite-conn-mgr/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -144,8 +144,16 @@ impl SqliteDatabase {
144144 drop ( conn) ; // Close immediately after creating the file
145145 }
146146
147+ // Enable PRAGMA optimize on close as recommended by SQLite for long-lived databases.
148+ // SQLite recommends analysis_limit values between 100-1000 for older versions;
149+ // SQLite 3.46.0+ handles limits automatically.
150+ // https://www.sqlite.org/lang_analyze.html#recommended_usage_pattern
151+ //
147152 // Create read pool with read-only connections
148- let read_options = SqliteConnectOptions :: new ( ) . filename ( & path) . read_only ( true ) ;
153+ let read_options = SqliteConnectOptions :: new ( )
154+ . filename ( & path)
155+ . read_only ( true )
156+ . optimize_on_close ( true , 400 ) ;
149157
150158 let read_pool = SqlitePoolOptions :: new ( )
151159 . max_connections ( config. max_read_connections )
@@ -157,7 +165,10 @@ impl SqliteDatabase {
157165 . await ?;
158166
159167 // Create write pool with a single read-write connection
160- let write_options = SqliteConnectOptions :: new ( ) . filename ( & path) . read_only ( false ) ;
168+ let write_options = SqliteConnectOptions :: new ( )
169+ . filename ( & path)
170+ . read_only ( false )
171+ . optimize_on_close ( true , 400 ) ;
161172
162173 let write_conn = SqlitePoolOptions :: new ( )
163174 . max_connections ( 1 )
You can’t perform that action at this time.
0 commit comments