Optimize Your SQLite Database with the Laravel Optimize DB Package

The Laravel Optimize DB package provides a good starting point for production-ready SQLite databases. Pest creator and core Laravel team member Nuno Maduro created this package.

This package is meant for SQLite (3.46+) in a Laravel project and works by applying migration to your project and runtime configuration applied via the package's service provider. It applies the following settings at the time of writing:

 ┌───────────────────────────┬─────────────┬───────────┐
 │ Setting                   │ Value       │ Via       │
 ├───────────────────────────┼─────────────┼───────────┤
 │ PRAGMA auto_vacuum        │ incremental │ Migration │
 │ PRAGMA journal_mode       │ WAL         │ Migration │
 │ PRAGMA page_size          │ 32768       │ Migration │
 │ PRAGMA busy_timeout       │ 5000        │ Runtime   │
 │ PRAGMA cache_size         │ -20000      │ Runtime   │
 │ PRAGMA foreign_keys       │ ON          │ Runtime   │
 │ PRAGMA incremental_vacuum │ (enabled)   │ Runtime   │
 │ PRAGMA mmap_size          │ 2147483648  │ Runtime   │
 │ PRAGMA temp_store         │ MEMORY      │ Runtime   │
 │ PRAGMA synchronous        │ NORMAL      │ Runtime   │
 └───────────────────────────┴─────────────┴───────────┘

High Impact Settings

I won't cover each setting, but the following three settings could potentially have a highly positive impact on SQLite performance.

journal_mode = WAL:

cache_size = -20000 (20 MB cache):

mmap_size = 2147483648 (2 GB memory mapping):

The package is considered a work-in-progress, so use it carefully. The package advises not to use it in production yet and to back up your database before requiring it. You can learn more about this package and view the source code on Github.


The post Optimize Your SQLite Database with the Laravel Optimize DB Package appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.