As I set up a new Laravel project with SQLite I’ve found many references to enabling Write Ahead Logging being a large performance boost. All of the blog posts I’ve seen say to use the after parameter in your database connection like this.

'sqlite' => [
    'driver' => 'sqlite',
    'url' => env('DATABASE_URL'),
    'database' => env('DB_DATABASE', database_path('database.sqlite')),
    'prefix' => '',
    'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
    'after' => function ($connection) {
        $connection->statement('PRAGMA journal_mode=WAL;');
    },
],

But when you look at a modern Laravel database connection you’ll see that there is a defined parameter for journal_mode but no documentation on how to set WAL using this parameter. Thanks to wew for pointing me to the proper Issue showing me how to add WAL using the journal_mode parameter. Now my database connection looks like this.

'sqlite' => [
	'driver' => 'sqlite',
	'url' => env('DB_URL'),
	'database' => env('DB_DATABASE', database_path('database.sqlite')),
	'prefix' => '',
	'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
	'busy_timeout' => 5000,
	'journal_mode' => 'WAL',
	'synchronous' => 'NORMAL',
],

Posted by Curtis McHale

Web developer specializing in membership and ecommerce sites. I like to ride my bicycle.

Leave a Reply

Your email address will not be published. Required fields are marked *