On 2/19/15, Jerry Krinock <jerry at ieee.org> wrote: > Assertion: If the size of the -wal file is 0 bytes, then this means that > the associated database has been checkpointed and, if I am sure that no > process has the database open, I can safely discard the -shm and -wal files, > and pass only the main database file, to another user say, with no fear of > data loss. > > Am I correct? >
Don't unlink the -wal file while SQLite is still running. A process under unix has no way of knowing that the file has been unlinked and will keep merrily using it, oblivious to the fact that it is gone. This can lead to serious troubles. Note that it is not possible to delete the -wal file on Windows while it is in use, so this is not an issue there. But apart from that, Yes it is safe to send just the database file if the WAL file is zero bytes in size. If SQLite is running, the best way to make a copy of the file to move to another machine is to use the backup API. The shell will let you do this from the command-line: sqlite3 running.db ".backup safe-to-copy.db" Or you can invoke the API directly from your application. Whatever is convenient. See https://www.sqlite.org/backup.html for additional information. You never need to preserve the -shm file (except of course while SQLite is running - don't mess with files that SQLite is actively using on posix!). The -shm is a performance boosting cache and will be automatically discarded and reconstructed from scratch the next time SQLite boots up anyhow. Only the -wal needs to be preserved after a crash. -- D. Richard Hipp drh at sqlite.org