SQLite is the default database of Exponential 6. A complete site runs from one file, with no database server to install, configure or secure. The driver is eZSQLite3DB on the PHP extension sqlite3, selected with DatabaseImplementation=sqlite3. The setup wizard preselects it when the extension is present.
Settings
[DatabaseSettings] DatabaseImplementation=sqlite3 Database=exponential.db SQLiteTransactionWait=25 #SQLitePragmas[]=journal_size_limit=67108864
- Database: a name without a slash lives in var/storage/sqlite3/; an absolute path is used as given.
- The journal runs in WAL mode, so readers and the writer work side by side. The driver's defaults are synchronous=NORMAL, a 64 MB cache, memory-mapped I/O, temp_store=MEMORY and busy_timeout=5000.
- Transactions start with BEGIN IMMEDIATE and wait for the write lock up to SQLiteTransactionWait seconds (25). Keep it below the request timeout of your web server, and raise both together.
Backup and restore
Never copy a database file that is in use. Use SQLite's online backup, which takes a consistent copy while the site keeps running, and check it:
sqlite3 var/storage/sqlite3/exponential.db ".backup '/backup/exponential.db'" sqlite3 /backup/exponential.db "PRAGMA integrity_check"
To restore, put the site in maintenance, use .restore, then clear the caches:
php bin/php/maintenance.php on --message="Restoring" sqlite3 var/storage/sqlite3/exponential.db ".restore '/backup/exponential.db'" php bin/php/maintenance.php off php bin/php/ezcache.php --clear-all php bin/php/console exp:velocity cache clear --apply
Maintenance
- Run ANALYZE once after an install or a large import; PRAGMA optimize is cheap enough for a weekly cron entry.
- VACUUM rebuilds the file compactly, but needs twice the database's size in free disk and holds the write lock: run it in maintenance mode.
- Make every file in var/storage/sqlite3/ group-writable for one common group of all processes, instead of world-writable modes.
- Check that the file is never served: curl -sI https://www.example.com/var/storage/sqlite3/exponential.db must not answer 200.
When to choose another engine
SQLite fits when the site runs on one machine and its write load is that of an editorial team, however many visitors read it. Choose PostgreSQL, MariaDB or MySQL when more than one machine must write the same database, when many editors publish large changes all day, or when you need replication or database users and grants. Size is rarely the reason.
On 7x hosting, 7x MasterRec runs SQLite sites on several servers with replicas and continuous backup.