在服务器应用程序中使用 Sqlite?备择方案?
Using Sqlite in a server application? Alternatives?
考虑以下场景:
数据库将在本地网络上使用,同时有少数客户端连接到该网络。有一个table。当其中一个客户端修改 table 中的数据时,应通知其他连接的客户端。也许每个连接在服务器应用程序中可能有一个线程。
一个约束是不应要求用户安装和配置任何其他第三方数据库软件。这就是为什么会想到 Sqlite,因为应用程序本身只能与 .db 文件交互,而后者可以与其捆绑在一起。
这是 Sqlite 可以实现的,还是这个想法完全错误和被误导了?
说明此描述的简单图表。
交流意见汇总:
答案是肯定的,您可以将 SQLite 用于此架构。
您可能还想启用 WAL(预写日志记录),以增加并发性:
...
There are advantages and disadvantages to using WAL instead of a rollback journal. Advantages include:
- WAL is significantly faster in most scenarios.
- WAL provides more concurrency as readers do not block writers and a writer does not block readers. Reading and writing can proceed concurrently.
- Disk I/O operations tends to be more sequential using WAL.
- WAL uses many fewer fsync() operations and is thus less vulnerable to problems on systems where the fsync() system call is broken.
But there are also disadvantages:
...
对于问题的通知部分,我建议调查triggers:
...
Triggers are database operations that are automatically performed when a specified database event occurs.
Each trigger must specify that it will fire for one of the following operations: DELETE, INSERT, UPDATE.
...
考虑以下场景: 数据库将在本地网络上使用,同时有少数客户端连接到该网络。有一个table。当其中一个客户端修改 table 中的数据时,应通知其他连接的客户端。也许每个连接在服务器应用程序中可能有一个线程。
一个约束是不应要求用户安装和配置任何其他第三方数据库软件。这就是为什么会想到 Sqlite,因为应用程序本身只能与 .db 文件交互,而后者可以与其捆绑在一起。
这是 Sqlite 可以实现的,还是这个想法完全错误和被误导了?
说明此描述的简单图表。
交流意见汇总:
答案是肯定的,您可以将 SQLite 用于此架构。
您可能还想启用 WAL(预写日志记录),以增加并发性:
... There are advantages and disadvantages to using WAL instead of a rollback journal. Advantages include:
- WAL is significantly faster in most scenarios.
- WAL provides more concurrency as readers do not block writers and a writer does not block readers. Reading and writing can proceed concurrently.
- Disk I/O operations tends to be more sequential using WAL.
- WAL uses many fewer fsync() operations and is thus less vulnerable to problems on systems where the fsync() system call is broken.
But there are also disadvantages: ...
对于问题的通知部分,我建议调查triggers:
... Triggers are database operations that are automatically performed when a specified database event occurs.
Each trigger must specify that it will fire for one of the following operations: DELETE, INSERT, UPDATE. ...