SQL SQLite 是否支持复制?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1888242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:44:04  来源:igfitidea点击:

Does SQLite support replication?

sqldatabase-designsqlitereplicationembedded-database

提问by kdt

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.

在嵌入 SQLite3 并使用内存数据库的应用程序中,是否可以在应用程序的两个运行实例之间复制数据库?我可以使用自制协议手动完成此操作,复制我的所有数据库访问,但这似乎应该在数据库层内完成。

采纳答案by Aaron Digulla

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.

蛮力方法:向它发送“.dump”命令以创建数据的文本表示。将该数据读入第二个数据库。不确定你可以使用它。

If you need a fine grained update (sending a copy of each upto the other copy), have a look at sqlite3_update_hook

如果您需要细粒度更新(将每个副本发送到另一个副本),请查看 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?

但是你打算如何处理错误?例如,当 app2 中的 DB 副本由于某种原因无法进行更新时会发生什么?

To solve this, move the database to a server process and have the two apps talk to it.

要解决此问题,请将数据库移至服务器进程并让两个应用程序与之对话。

回答by O'Rooney

Out of the box, no. There are a small number of third-party options:

开箱即用,没有。有少量第三方选项:

SQLite sync: https://ampliapps.com/sqlite-sync/This one seems attractive because it can replicate to other databases as well as SQLite, and doesn't modify the SQLite engine. I haven't tried it yet.

SQLite 同步:https: //ampliapps.com/sqlite-sync/这个看起来很有吸引力,因为它可以复制到其他数据库以及 SQLite,并且不会修改 SQLite 引擎。我还没试过。

Litereplica: http://litereplica.io/One way only. Seems to have been around a bit.

Litereplica:http://litereplica.io/仅一种方式。好像有点过了。

LiteSync: http://litesync.io/Two-way replication. Pretty new, but an evolution of Litereplica so probably more mature than it appears. I have tried this a bit and it does seem to work smoothly, with a few bugs which the developer is looking at. You have to use the developer's modified SQLite engine, which seems like a concerning dependency. You also don't get much control, e.g. you can't say replicate now without reopening the database.

LiteSync:http://litesync.io/双向复制。相当新,但 Litereplica 的演变可能比它看起来更成熟。我已经尝试了一点,它似乎工作顺利,开发人员正在查看一些错误。您必须使用开发人员修改后的 SQLite 引擎,这似乎是一个相关的依赖项。您也没有太多控制权,例如,您不能在不重新打开数据库的情况下说“现在复制”。

回答by cyrus.y

Lsyncd - Live Syncing (Mirror) Daemonmay be of use here. It uses rsync to do continuous replication on the file level.

Lsyncd - Live Syncing (Mirror) Daemon可能在这里有用。它使用 rsync 在文件级别进行连续复制。

回答by Hassan Syed

If you want replication in an in-memory database you need to look at berkeley DB (BDB). However the data model for BDB is string-string dictionary, so you loose the flexibility of SQL. plus it has a three clause license, so if your project is commercial you need to get licenses.

如果您想在内存数据库中进行复制,则需要查看berkeley DB (BDB)。但是,BDB 的数据模型是字符串-字符串字典,因此失去了 SQL 的灵活性。加上它有一个三条款许可证,所以如果你的项目是商业项目,你需要获得许可证。

回答by Rich K.

Unison? Best you could do though was hot spare, because SQLite db in one monolithic file. You couldn't round-robin between the two "instances". Hot spare isn't bad, you simply pick up the other app+db without much fuss, compare to MySQL master-slave or active-passive where there is some manual intervention which is not easy. MySQL replication passes around SQL, not just diffs like unison/rsync. But with unison you have master-master.

齐心协力?你能做的最好的事情是热备份,因为 SQLite db 在一个整体文件中。你不能在两个“实例”之间循环。热备也不错,你只需拿起其他的应用程序+数据库就不会大惊小怪,相比 MySQL 主从或主动-被动,那里有一些人工干预并不容易。MySQL 复制传递 SQL,而不仅仅是像 unison/rsync 这样的差异。但是,如果您齐心协力,您就拥有了主人。

回答by Taneli Waltari

No it doesn't because the project's scope is being a simple in-process database. But because the database is just a single file, you could write your own replication script based on plain file copy operations, rsync or something similar.

不,不是因为项目的范围是一个简单的进程内数据库。但是因为数据库只是一个文件,你可以根据普通文件复制操作、rsync 或类似的东西编写自己的复制脚本。

If you really want a SQLite based client/server type of RDBMS, you could take a look at SQLiteDBMS.

如果你真的想要一个基于 SQLite 的客户端/服务器类型的 RDBMS,你可以看看SQLiteDBMS