SQLiteSQLite错误代码
SQLITE_BUSY
busy
其他表示形式:5
这是什么问题?
代码 SQLITE_BUSY · SQLite 报告的问题。
译文说明
SQLITE_BUSY 结果代码表示由于某些其他数据库连接(通常是单独进程中的数据库连接)的并发活动,无法写入(或在某些情况下读取)数据库文件。
例如,如果进程 A 正在进行一个大型写事务,同时进程 B 尝试启动一个新的写事务,则进程 B 将返回 SQLITE_BUSY 结果,因为 SQLite 一次只支持一个写入者。进程 B 需要等待进程 A 完成其事务才能开始新事务。 sqlite3_busy_timeout() 和 sqlite3_busy_handler() 接口以及 busy_timeout 编译指示可用于进程 B 以帮助其处理 SQLITE_BUSY 错误。
SQLITE_BUSY 错误可能发生在事务中的任何点:事务首次启动时、任何写入或更新操作期间或事务提交时。为了避免在事务中间遇到 SQLITE_BUSY 错误,应用程序可以使用 BEGIN IMMEDIATE 而不仅仅是 BEGIN 来启动事务。 BEGIN IMMEDIATE 命令本身可能返回 SQLITE_BUSY,但如果成功,则 SQLite 保证通过下一次 COMMIT 对同一数据库执行的任何后续操作都不会返回 SQLITE_BUSY。
另请参见:SQLITE_BUSY_RECOVERY 和 SQLITE_BUSY_SNAPSHOT。
SQLITE_BUSY 结果代码与 SQLITE_LOCKED 的不同之处在于,SQLITE_BUSY 指示与单独的数据库连接(可能在单独的进程中)发生冲突,而 SQLITE_LOCKED 指示同一数据库连接(或有时与共享缓存的数据库连接)内的冲突。
Google Translate · 此内容为自动翻译。技术术语及适用条件请以英文原文为准。
官方说明 · 原文
The SQLITE_BUSY result code indicates that the database file could not be written (or in some cases read) because of concurrent activity by some other database connection, usually a database connection in a separate process.
For example, if process A is in the middle of a large write transaction and at the same time process B attempts to start a new write transaction, process B will get back an SQLITE_BUSY result because SQLite only supports one writer at a time. Process B will need to wait for process A to finish its transaction before starting a new transaction. The sqlite3_busy_timeout() and sqlite3_busy_handler() interfaces and the busy_timeout pragma are available to process B to help it deal with SQLITE_BUSY errors.
An SQLITE_BUSY error can occur at any point in a transaction: when the transaction is first started, during any write or update operations, or when the transaction commits. To avoid encountering SQLITE_BUSY errors in the middle of a transaction, the application can use BEGIN IMMEDIATE instead of just BEGIN to start a transaction. The BEGIN IMMEDIATE command might itself return SQLITE_BUSY, but if it succeeds, then SQLite guarantees that no subsequent operations on the same database through the next COMMIT will return SQLITE_BUSY.
See also: SQLITE_BUSY_RECOVERY and SQLITE_BUSY_SNAPSHOT.
The SQLITE_BUSY result code differs from SQLITE_LOCKED in that SQLITE_BUSY indicates a conflict with a separate database connection, probably in a separate process, whereas SQLITE_LOCKED indicates a conflict within the same database connection (or sometimes a database connection with a shared cache).
故障排除与诊断链接
请先确认文档中的产品、版本及发生环境与当前情况一致。
- 通用诊断指南
检查锁等待时间与 busy handler ↗
针对该代码 · 请确认适用环境
- 代码参考
结果代码含义与处理方式的官方说明 ↗
定义与说明 · 非故障排除步骤
来源与使用条款
作者:SQLite authors / Hwaci
许可证:Public domain dedication (SQLite code and documentation)
核查日期:2026-11-12
修改记录:English prose extracted; whitespace normalized; Korean context and classified official links added. Python code examples not redistributed. 译文说明已标注为自动翻译。