A faster way to copy SQLite databases between computers
Approaches to copying SQLite databases
- Many see the article’s SQL-dump-over-ssh approach as standard practice across databases: dump on source, pipe over network, recreate on destination.
- Several suggest simplifying to a single pipeline (no temp files), e.g. remote
.dumppiped directly into localsqlite3. - Others favor copying the DB file itself using
scporrsync, especially when indexes should be preserved and bandwidth is not the bottleneck.
Compression choices and performance
- Suggestions to replace
gzipwithzstd(or sometimesbrotli,lz4,pigz/igzip) due to better compression ratios and throughput. - Debate on whether compression helps only on slow links vs almost always (because CPU is usually faster than disk/network).
- Benchmarks shared: zstd can reach multi-GB/s on large files, but real-world speeds and benefits depend heavily on data type, file size, and hardware.
- Some note that compressing text dumps vs compressed SQLite binaries gives modest size differences; in one example, text+gzip was smaller, in another, raw DB+zstd won when indexes were removed.
Incremental sync vs one-off snapshots
- Several argue incremental backup via
rsync(orsqlite3_rsync) is generally faster than repeated full dumps, especially when data changes are small. - For one-off or occasional transfers over slow links, text dumps without indexes can be faster overall despite rebuild costs.
rsync -zis highlighted as a simpler alternative, though some point out that precompressing defeats rsync’s delta algorithm.
Safety and consistency for live databases
- Strong warnings that naïvely copying a live SQLite file can corrupt or produce inconsistent databases.
- Recommended options:
- SQLite’s
.backup/ backup API. VACUUM INTOto create a compact, consistent copy.- Filesystem or block-level snapshots (LVM, ZFS, Btrfs), combined with WAL guarantees.
- Dedicated tools like Litestream or SQLite’s
sqlite3_rsync.
- SQLite’s
- Discussion acknowledges subtleties around WAL, crash consistency, and snapshot behavior.
Indexes, size, and rebuild cost
- Core idea of the article—skip indexes during transfer—receives mixed reactions:
- Pro: avoids sending often-massive index pages that compress poorly.
- Con: index recomputation can dominate time for large DBs; some workflows show tens of minutes spent on bulk inserts + index builds.
- Examples of schemas where index size greatly exceeds data, justified by query performance needs.
Alternative formats and tooling
- DuckDB suggested for exporting SQLite data to Parquet (with zstd), yielding dramatically smaller, analytics-friendly files; but this typically omits indexes and full schema unless using
EXPORT DATABASE. - SQLite session extension mentioned for change-data capture and offline-first sync use cases.
- Other ecosystem parallels: PostgreSQL (
pg_dump/pg_basebackup, replication), ZFS snapshots, Git with custom SQLite diffs.