sqlite-single-writer

Implement cross-process file locking to serialize SQLite writes in multi-process applications.

Updated Feb 21, 2026
One-click install
npx skills add https://github.com/joySUSY/violet-plugin-place --skill sqlite-single-writer-joysusy
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sqlite-single-writer
Source: https://github.com/joySUSY/violet-plugin-place/tree/main/plugins/developer-tool/modules/sqlite-single-writer
Command: npx skills add https://github.com/joySUSY/violet-plugin-place --skill sqlite-single-writer-joysusy

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires fs2, rusqlite, chrono, better-sqlite3, proper-lockfile, and includes references (resource) components.

What problem does it solve? SQLite allows only one writer at a time, so concurrent writes from multiple processes trigger SQLITE_BUSY errors and lost updates. This Skill provides a cross-platform single-writer queue pattern that serializes writes while keeping reads concurrent. ## Core Features & Use Cases - Cross-Platform File Locking: Uses flock on Unix and LockFileEx on Windows with exponential backoff and automatic lock release on process crash. - WAL Mode Configuration: Enables Write-Ahead Logging so reads stay concurrent while writes are serialized through a separate lock file. - Diagnostic Timeout Errors: Writes holder PID and timestamp into the lock file so timeout errors identify the blocking process. - Use Case: A CLI tool or agent system where several processes write to a shared local SQLite database can wrap every write in the lock pattern to guarantee no writes are lost. ## Quick Start Ask the AI to implement the SQLite single-writer locking pattern with WAL mode for your Go, Rust, Python, or Node.js application.

Frequently Asked Questions about sqlite-single-writer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent SQLITE_BUSY errors with multiple processes?▼

Use a separate lock file with OS-level exclusive locking (flock on Unix, LockFileEx on Windows) to serialize writes across processes. Enable WAL mode so reads remain concurrent while writes queue through the lock.

How to implement SQLite write locking in Python?▼

Use fcntl.flock with LOCK_EX and LOCK_NB on Unix, or msvcrt.locking on Windows, against a dedicated db.lock file. Retry with exponential backoff starting at 5ms and raise a timeout error with holder info after 500ms.

Does WAL mode allow concurrent SQLite reads and writes?▼

Yes, WAL mode lets readers proceed while a single writer holds the database. Enable it with PRAGMA journal_mode=WAL along with busy_timeout=500 and synchronous=NORMAL on every connection.

What happens to the file lock if a process crashes?▼

Both flock and LockFileEx are automatically released by the operating system when the holding process exits or crashes. The lock file content may be stale, but the lock itself is never held by a dead process.

Can I use flock for SQLite locking on NFS or network drives?▼

No, flock is unreliable on NFS and SMB network filesystems. This pattern only works on local filesystems; for network storage you need a different coordination mechanism or a client-server database.

Why use a separate lock file instead of locking the database file?▼

SQLite manages its own internal locks on the database file, and external locking can interfere with WAL and shared-memory files. A separate db.lock file coordinates writers without conflicting with SQLite's locking.