我可以从多个连接同时读取和写入 SQLite 数据库吗? [英] Can I read and write to a SQLite database concurrently from multiple connections?

查看:96
本文介绍了我可以从多个连接同时读取和写入 SQLite 数据库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由两个进程使用的 SQLite 数据库.我想知道,使用最新版本的 SQLite,当一个进程(连接)启动一个写入数据库的事务时,另一个进程是否能够同时从数据库中读取?

I have a SQLite database that is used by two processes. I am wondering, with the most recent version of SQLite, while one process (connection) starts a transaction to write to the database will the other process be able to read from the database simultaneously?

推荐答案

我从各种来源收集信息,主要来自 sqlite.org,并将它们放在一起:

I collected information from various sources, mostly from sqlite.org, and put them together:

首先,默认情况下,多个进程可以同时打开同一个SQLite数据库,可以同时满足多个读访问.

First, by default, multiple processes can have the same SQLite database open at the same time, and several read accesses can be satisfied in parallel.

在写入的情况下,对数据库的单次写入会在短时间内锁定数据库,任何东西,甚至读取,都无法访问数据库文件.

In case of writing, a single write to the database locks the database for a short time, nothing, even reading, can access the database file at all.

从 3.7.0 版开始,一个新的Write Ahead Logging" (WAL) 选项可用,其中读和写可以同时进行.

Beginning with version 3.7.0, a new "Write Ahead Logging" (WAL) option is available, in which reading and writing can proceed concurrently.

默认情况下,WAL 未启用.要打开 WAL,请参阅 SQLite 文档.

By default, WAL is not enabled. To turn WAL on, refer to the SQLite documentation.

这篇关于我可以从多个连接同时读取和写入 SQLite 数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆