On Sun, 6 Oct 2019 at 23:27, Kadirk <kadirkaracel...@gmail.com> wrote:
> How to do online backup of an in memory database (to disk)? > > Planning to use in memory database with 10 gb+ data, there are queries > continuously so stopping application is not an option. Looks like for on > disk databases it is possible with a non-blocking fashion but I couldn't > find a way to do it for in memory database. Whenever an update comes in, > backup process starts over so it won't finish. Any idea how to solve this? > Huh, the documentation explicitly points this out: If another thread or process writes to the source database while this > function is sleeping, then SQLite detects this and usually restarts the > backup process when sqlite3_backup_step() is next called. There is one > exception to this rule: If the source database is not an in-memory > database, and the write is performed from within the same process as the > backup operation and uses the same database handle (pDb), then the > destination database (the one opened using connection pFile) is > automatically updated along with the source. > https://www.sqlite.org/backup.html Seems like a strange exception, I wonder why it's there? You could still complete the backup by specifying nPage=-1 to sqlite3_backup_step -- this requires a read lock for the duration, but the lock methods appear to be a no-op for in-memory DBs. Presumably holding the DB's mutex will still prevent other threads from accessing it though. Another option if you're on linux is to put the DB file in /dev/shm, at which point it is physically in memory but from sqlite's perspective is a regular disk file. You'd have to check the performance characteristics again of course. -Rowan _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users