找回密码
 新建账号

database is locked in ... SQLite

[复制链接]
php 发表于 2020/6/1 13:50 | 显示全部楼层 |阅读模式
PHP PDO SQLite database is locked in C:\server\www\wuxiancheng.cn\index.php

PHP SQLite,包括 PDO SQLite 驱动和 sqlite_* 函数以及 SQLite3 类,只要使用了 SQLite,都可能出现 database is locked 这个问题。

其他程序语言,只要使用 SQLite 数据库,也存在这个问题。

SQLite 的阻塞机制会导致数据库忙被锁死,如果阻塞时间过长,就会现出 database is locked 这个错误。

可以将默认的使用 SQL 语句 PRAGMA journal_mode=WAL 将 journal_mode 改为 WAL,避免读写互相阻塞。

journal_mode 的值可以是 DELETE | TRUNCATE | PERSIST | MEMORY | WAL | OFF 之一,其中 DELETE 是默认值。

如果使用默认值 DELETE,SQLite 会生成回滚日志文件(the rollback journal),操作完成后会立即删除回滚日志文件,下次又会回生成滚日志文件,然后删除回滚日志文件,循环往复,增大磁盘 I/O 开销。

另一方面,操作完数据库后要尽早关闭数据库连接,释放资源,不要等到自动回收资源。

要了解更多细节,可以点击访问最下方提供的 SQLite 官方链接。

The default method by which SQLite implements atomic commit and rollback is a rollback journal. Beginning with version 3.7.0 (2010-07-21), a new "Write-Ahead Log" option (hereafter referred to as "WAL") is available.

There are advantages to using WAL instead of a rollback journal:

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.

https://www.sqlite.org/wal.html
https://www.sqlite.org/lockingv3.html
https://www.sqlite.org/pragma.html#pragma_journal_mode

手机版|轻松E站

GMT+8, 2024/12/22 00:40

快速回复 返回顶部 返回列表