I have two small devices, A and B. Device A continuously reads and writes to a SQLite database in WAL mode called mydata.sqlite.
At regular intervals, a different process synchronizes this file from Device A → B using the tool sqlite3_rsync over a normal network connection.
The problem I encounter is that on device B, the database becomes malformed at irregular intervals. Once this happens, all subsequent sqlite3_rsync operations from A to B fail with the following error:
ERROR: SQL statement [ATTACH %Q AS 'replica'] failed: database disk image is malformed
Databases were not synced due to errors
When I run an integrity check on the database after the error occured on device B I get:
# sqlite3 mydata.sqlite "PRAGMA integrity_check;"
Error: in prepare, database disk image is malformed (11)
The corruption only occurs on the target B. If I delete the file on device B, the next sync recreates it cleanly. The issue happens sporadically, not on every synchronization.
What conditions can cause sqlite3_rsync to generate a corrupted database on the target? Are there operations on device A that must not run during sync (e .g. , writes, VACUUM, WAL checkpoints, open transactions, file locks)?