SQLite
Use SQLite correctly with proper concurrency, pragmas, and type handling.
Iván
@ivangdavila
What This Skill Does
Provides best practices for using SQLite, covering concurrency, pragmas, type handling, schema changes, performance tuning, and backup safety. Includes specific SQL commands and configuration settings to avoid common pitfalls.
Eliminates silent data corruption and concurrency errors by enforcing proper SQLite configuration like WAL mode, busy timeout, and foreign key enforcement.
When to Use It
- Enable WAL mode and set busy timeout for a multi-threaded application using SQLite
- Turn on foreign key enforcement per connection to maintain referential integrity
- Use STRICT tables to enforce column types in SQLite 3.37+
- Batch insert thousands of rows inside a single transaction for 10-100x speedup
- Vacuum a database after bulk deletes to reclaim disk space
- Backup a live SQLite database safely using the .backup command or VACUUM INTO
Install
$ openclaw skills install @ivangdavila/sqliteConcurrency (Biggest Gotcha)
- Only one writer at a time—concurrent writes queue or fail; not for high-write workloads
- Enable WAL mode:
PRAGMA journal_mode=WAL—allows reads during writes, huge improvement - Set busy timeout:
PRAGMA busy_timeout=5000—waits 5s before SQLITE_BUSY instead of failing immediately - WAL needs
-waland-shmfiles—don't forget to copy them with main database BEGIN IMMEDIATEto grab write lock early—prevents deadlocks in read-then-write patterns
Foreign Keys (Off by Default!)
PRAGMA foreign_keys=ONrequired per connection—not persisted in database- Without it, foreign key constraints silently ignored—data integrity broken
- Check before relying:
PRAGMA foreign_keysreturns 0 or 1 - ON DELETE CASCADE only works if foreign_keys is ON
Type System
- Type affinity, not strict types—INTEGER column accepts "hello" without error
STRICTtables enforce types—but only SQLite 3.37+ (2021)- No native DATE/TIME—use TEXT as ISO8601 or INTEGER as Unix timestamp
- BOOLEAN doesn't exist—use INTEGER 0/1; TRUE/FALSE are just aliases
- REAL is 8-byte float—same precision issues as any float
Schema Changes
ALTER TABLEvery limited—can add column, rename table/column; that's mostly it- Can't change column type, add constraints, or drop columns (until 3.35)
- Workaround: create new table, copy data, drop old, rename—wrap in transaction
ALTER TABLE ADD COLUMNcan't have PRIMARY KEY, UNIQUE, or NOT NULL without default
Performance Pragmas
PRAGMA optimizebefore closing long-running connections—updates query planner statsPRAGMA cache_size=-64000for 64MB cache—negative = KB; default very smallPRAGMA synchronous=NORMALwith WAL—good balance of safety and speedPRAGMA temp_store=MEMORYfor temp tables in RAM—faster sorts and temp results
Vacuum & Maintenance
- Deleted data doesn't shrink file—
VACUUMrewrites entire database, reclaims space VACUUMneeds 2x disk space temporarily—ensure enough roomPRAGMA auto_vacuum=INCREMENTALwithPRAGMA incremental_vacuum—partial reclaim without full rewrite- After bulk deletes, always vacuum or file stays bloated
Backup Safety
- Never copy database file while open—corrupts if write in progress
- Use
.backupcommand in sqlite3—orsqlite3_backup_*API - WAL mode:
-waland-shmmust be copied atomically with main file VACUUM INTO 'backup.db'creates standalone copy (3.27+)
Indexing
- Covering indexes work—add extra columns to avoid table lookup
- Partial indexes supported (3.8+):
CREATE INDEX ... WHERE condition - Expression indexes (3.9+):
CREATE INDEX ON t(lower(name)) EXPLAIN QUERY PLANshows index usage—simpler than PostgreSQL EXPLAIN
Transactions
- Autocommit by default—each statement is own transaction; slow for bulk inserts
- Batch inserts:
BEGIN; INSERT...; INSERT...; COMMIT—10-100x faster BEGIN EXCLUSIVEfor exclusive lock—blocks all other connections- Nested transactions via
SAVEPOINT name/RELEASE name/ROLLBACK TO name
Common Mistakes
- Using SQLite for web app with concurrent users—one writer blocks all; use PostgreSQL
- Assuming ROWID is stable—
VACUUMcan change ROWIDs; use explicit INTEGER PRIMARY KEY - Not setting busy_timeout—random SQLITE_BUSY errors under any concurrency
- In-memory database
':memory:'—each connection gets different database; usefile::memory:?cache=sharedfor shared
Top skills in this category
Skill Vetter
@spclaudehomeSecurity-first skill vetting for AI agents. Use before installing any skill from ClawdHub, GitHub, or other sources. Checks for red flags, permission scope, and suspicious patterns.
Github
@steipeteInteract with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Humanizer
@biostartechnologyRemove signs of AI-generated writing from text. Use when editing or reviewing text to make it sound more natural and human-written. Based on Wikipedia's comprehensive "Signs of AI writing" guide. Detects and fixes patterns including: inflated symbolism, promotional language, superficial -ing analyses, vague attributions, em dash overuse, rule of three, AI vocabulary words, negative parallelisms, and excessive conjunctive phrases.
Free Ride - Unlimited free AI
@shaivpidadiManages free AI models from OpenRouter for OpenClaw. Automatically ranks models by quality, configures fallbacks for rate-limit handling, and updates opencla...
Elite Longterm Memory
@nextfrontierbuildsUltimate AI agent memory system for Cursor, Claude, ChatGPT & Copilot. WAL protocol + vector search + git-notes + cloud backup. Never lose context again. Vibe-coding ready.