Litestream
Litestream is a disaster recovery tool for SQLite that runs as a background process, continuously replicating database changes to cloud storage. It monitors the SQLite Write-Ahead Log (WAL), converts changes to immutable LTX files, and uploads them to your chosen storage backend.
Key Concepts
- WAL Monitoring: Watches SQLite Write-Ahead Log for changes at configurable intervals (default 1s)
- LTX Files: Immutable files containing database page changes, never modified after creation
- Level-Based Compaction: Multi-level system (L0-L9) that merges LTX files to reduce storage overhead
- Point-in-Time Recovery: Restore to any transaction using TXID or timestamp
- VFS Support: Read replicas directly from cloud storage without local database copy
- MCP Server: AI tool integration for automated database management
Quick Start
Installation
# macOS
brew install litestream
# Linux (Debian/Ubuntu)
wget https://github.com/benbjohnson/litestream/releases/download/v0.5.5/litestream-v0.5.5-linux-amd64.deb
sudo dpkg -i litestream-v0.5.5-linux-amd64.deb
# Docker
docker pull litestream/litestream:0.5
Basic Replication
# Command line (single database)
litestream replicate /path/to/db.sqlite s3://bucket/db
# With config file
litestream replicate -config /etc/litestream.yml
Restore Database
# Restore latest backup
litestream restore -o /path/to/restored.db s3://bucket/db
# Point-in-time recovery
litestream restore -timestamp 2024-01-15T10:30:00Z -o /tmp/db s3://bucket/db
# Restore to specific transaction
litestream restore -txid 1000 -o /tmp/db s3://bucket/db
Check Status
# View all databases and their replication status
litestream status
# List available LTX files
litestream ltx /path/to/db.sqlite
Critical Rules
These rules are essential for correct Litestream operation:
Lock Page at 1GB: SQLite reserves the page at offset 0x40000000 (1GB). This page must always be skipped during replication and compaction. The page number varies by page size:
- 4KB pages: page 262145
- 8KB pages: page 131073
- 16KB pages: page 65537
LTX Files are Immutable: Once created, LTX files are never modified. New changes create new files.
Single Replica per Database: Each database can only replicate to one destination. Use multiple Litestream instances for multiple destinations.
WAL Mode Required: SQLite must be in WAL mode (PRAGMA journal_mode=WAL;)
Use litestream ltx: The litestream wal command is deprecated.
Storage Backends
| Backend |
URL Scheme |
Example |
| AWS S3 |
s3:// |
s3://bucket/path |
| S3-Compatible (R2, Tigris, MinIO) |
s3:// |
s3://bucket/path?endpoint=host:port |
| Google Cloud Storage |
gs:// |
gs://bucket/path |
| Azure Blob Storage |
abs:// |
abs://container@account/path |
| SFTP |
sftp:// |
sftp://user@host:22/path |
| NATS JetStream |
nats:// |
nats://host:4222/bucket |
| WebDAV |
webdav:// |
webdav://host/path |
| Alibaba OSS |
oss:// |
oss://bucket/path |
| Local File |
(path) |
/var/backups/db |
Configuration File Example
dbs:
- path: /data/app.db
replica:
url: s3://my-bucket/app-backup
access-key-id: ${AWS_ACCESS_KEY_ID}
secret-access-key: ${AWS_SECRET_ACCESS_KEY}
region: us-east-1
sync-interval: 1s
When to Use This Skill
Use Litestream skill when:
- Configuring SQLite database replication to cloud storage
- Setting up disaster recovery for SQLite applications
- Troubleshooting replication issues (WAL growth, sync failures)
- Implementing point-in-time recovery procedures
- Deploying Litestream with Docker, Fly.io, Kubernetes, or systemd
- Understanding WAL-based replication concepts
Skill Contents
concepts/ - Architecture, replication mechanics, LTX format, SQLite WAL, VFS support, compaction
configuration/ - Storage backend configurations (S3, GCS, Azure, SFTP, NATS, OSS, WebDAV, File)
commands/ - CLI command reference (replicate, restore, status, ltx, databases)
operations/ - Monitoring, troubleshooting, recovery, and heartbeat monitoring
deployment/ - Docker, Fly.io, Kubernetes, and systemd deployment guides
integrations/ - MCP server integration for AI tools
scripts/ - Validation and diagnostic helper scripts
Common Issues
WAL Growing Too Large
- Check sync interval (default 1s may be too slow for write-heavy workloads)
- Verify storage backend connectivity
- Check for checkpoint blocking (long-running transactions)
Replication Lag
- Monitor with
litestream status
- Check network connectivity to storage backend
- Review sync interval configuration
Restore Failures
- Verify backup exists:
litestream ltx /path/to/db
- Check storage backend credentials
- Ensure target directory is writable
Links
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: litestream3description: SQLite disaster recovery and streaming replication to cloud storage (S3, GCS, Azure, SFTP, NATS). Use this skill for configuring Litestream, deploying to cloud platforms, troubleshooting WAL replication issues, implementing point-in-time recovery, and setting up VFS read replicas. Use when this capability is needed.4---56# Litestream78Litestream is a disaster recovery tool for SQLite that runs as a background process, continuously replicating database changes to cloud storage. It monitors the SQLite Write-Ahead Log (WAL), converts changes to immutable LTX files, and uploads them to your chosen storage backend.910## Key Concepts1112- **WAL Monitoring**: Watches SQLite Write-Ahead Log for changes at configurable intervals (default 1s)13- **LTX Files**: Immutable files containing database page changes, never modified after creation14- **Level-Based Compaction**: Multi-level system (L0-L9) that merges LTX files to reduce storage overhead15- **Point-in-Time Recovery**: Restore to any transaction using TXID or timestamp16- **VFS Support**: Read replicas directly from cloud storage without local database copy17- **MCP Server**: AI tool integration for automated database management1819## Quick Start2021### Installation2223```bash24# macOS25brew install litestream2627# Linux (Debian/Ubuntu)28wget https://github.com/benbjohnson/litestream/releases/download/v0.5.5/litestream-v0.5.5-linux-amd64.deb29sudo dpkg -i litestream-v0.5.5-linux-amd64.deb3031# Docker32docker pull litestream/litestream:0.533```3435### Basic Replication3637```bash38# Command line (single database)39litestream replicate /path/to/db.sqlite s3://bucket/db4041# With config file42litestream replicate -config /etc/litestream.yml43```4445### Restore Database4647```bash48# Restore latest backup49litestream restore -o /path/to/restored.db s3://bucket/db5051# Point-in-time recovery52litestream restore -timestamp 2024-01-15T10:30:00Z -o /tmp/db s3://bucket/db5354# Restore to specific transaction55litestream restore -txid 1000 -o /tmp/db s3://bucket/db56```5758### Check Status5960```bash61# View all databases and their replication status62litestream status6364# List available LTX files65litestream ltx /path/to/db.sqlite66```6768## Critical Rules6970These rules are essential for correct Litestream operation:71721. **Lock Page at 1GB**: SQLite reserves the page at offset 0x40000000 (1GB). This page must always be skipped during replication and compaction. The page number varies by page size:73 - 4KB pages: page 26214574 - 8KB pages: page 13107375 - 16KB pages: page 6553776772. **LTX Files are Immutable**: Once created, LTX files are never modified. New changes create new files.78793. **Single Replica per Database**: Each database can only replicate to one destination. Use multiple Litestream instances for multiple destinations.80814. **WAL Mode Required**: SQLite must be in WAL mode (`PRAGMA journal_mode=WAL;`)82835. **Use `litestream ltx`**: The `litestream wal` command is deprecated.8485## Storage Backends8687| Backend | URL Scheme | Example |88|---------|-----------|---------|89| AWS S3 | `s3://` | `s3://bucket/path` |90| S3-Compatible (R2, Tigris, MinIO) | `s3://` | `s3://bucket/path?endpoint=host:port` |91| Google Cloud Storage | `gs://` | `gs://bucket/path` |92| Azure Blob Storage | `abs://` | `abs://container@account/path` |93| SFTP | `sftp://` | `sftp://user@host:22/path` |94| NATS JetStream | `nats://` | `nats://host:4222/bucket` |95| WebDAV | `webdav://` | `webdav://host/path` |96| Alibaba OSS | `oss://` | `oss://bucket/path` |97| Local File | (path) | `/var/backups/db` |9899## Configuration File Example100101```yaml102dbs:103 - path: /data/app.db104 replica:105 url: s3://my-bucket/app-backup106 access-key-id: ${AWS_ACCESS_KEY_ID}107 secret-access-key: ${AWS_SECRET_ACCESS_KEY}108 region: us-east-1109 sync-interval: 1s110```111112## When to Use This Skill113114Use Litestream skill when:115- Configuring SQLite database replication to cloud storage116- Setting up disaster recovery for SQLite applications117- Troubleshooting replication issues (WAL growth, sync failures)118- Implementing point-in-time recovery procedures119- Deploying Litestream with Docker, Fly.io, Kubernetes, or systemd120- Understanding WAL-based replication concepts121122## Skill Contents123124- `concepts/` - Architecture, replication mechanics, LTX format, SQLite WAL, VFS support, compaction125- `configuration/` - Storage backend configurations (S3, GCS, Azure, SFTP, NATS, OSS, WebDAV, File)126- `commands/` - CLI command reference (replicate, restore, status, ltx, databases)127- `operations/` - Monitoring, troubleshooting, recovery, and heartbeat monitoring128- `deployment/` - Docker, Fly.io, Kubernetes, and systemd deployment guides129- `integrations/` - MCP server integration for AI tools130- `scripts/` - Validation and diagnostic helper scripts131132## Common Issues133134### WAL Growing Too Large135- Check sync interval (default 1s may be too slow for write-heavy workloads)136- Verify storage backend connectivity137- Check for checkpoint blocking (long-running transactions)138139### Replication Lag140- Monitor with `litestream status`141- Check network connectivity to storage backend142- Review sync interval configuration143144### Restore Failures145- Verify backup exists: `litestream ltx /path/to/db`146- Check storage backend credentials147- Ensure target directory is writable148149## Links150151- [Official Documentation](https://litestream.io)152- [GitHub Repository](https://github.com/benbjohnson/litestream)153- [Getting Started Guide](https://litestream.io/getting-started/)154155---156> Converted and distributed by [TomeVault](https://tomevault.io/claim/benbjohnson) — claim your Tome and manage your conversions.157<!-- tomevault:4.0:skill_md:2026-04-11 -->