In an application which embeds SQLite3 and uses an in-memory database, is it possible to replicate the database between two running instances of the application? I could do this by hand with a homebrew protocol duplicating all my DB accesses, but it seems like something that should be done inside the DB layer.
An SQLite database is limited in size to 281 terabytes (248 bytes, 256 tibibytes). And even if it could handle larger databases, SQLite stores the entire database in a single disk file and many filesystems limit the maximum size of files to something less than this.
SQLite doesn't support any kind of concurrency, so you may have problems running it on a production website.
Also, sqlite3 has a deceptively simple mechanism for ensuring maximum concurrency (which is also thread-safe) as described in their File locking and Concurrency document.
Overview. Usually, SQLite allows at most one writer to proceed concurrently. The BEGIN CONCURRENT enhancement allows multiple writers to process write transactions simultanously if the database is in "wal" or "wal2" mode, although the system still serializes COMMIT commands.
These replicas can be handled by the same application or another one, in the same device or a distant one. Each connection can use a different communication protocol, and a different connection direction. Updates in the replicas use the internal SQLite transaction engine at the pager level.
SQL Server Replication. Replication is a set of technologies for copying and distributing data and database objects from one database to another and then synchronizing between databases to maintain consistency.
For example say you have a cluster of three application nodes, all sharing the same distributed dqlite database. If one node fails or is shutdown for maintenance, then the remaining two nodes can continue to access the database and operate normally. Here follow the details about what SQLite data is actually replicated and how.
You can also use CopyCat, which support SQLite as well as a few other database types. Apparently it only supports SQLite under very limited conditions (e.g. using Delphi?!)
Brute force approach: Send it the ".dump" command to create a text representation of the data. Read that data in into the second database. Not sure you can use that.
If you need a fine grained update (sending a copy of each upto the other copy), have a look at sqlite3_update_hook
But how do you plan to handle errors? For example, what happens when the copy of the DB in app2 can't make an update for some reason?
To solve this, move the database to a server process and have the two apps talk to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With