用sqlite增加锁超时时间,默认值是多少?

Increase the lock timeout with sqlite, and what is the default values?

许多客户端查询 sqlite 数据库时的众所周知的问题:数据库被锁定
我想增加 linux 上锁定释放的等待延迟(以毫秒为单位)以消除此错误。

从 sqlite-command,我可以使用例如(4 秒):

sqlite> .timeout 4000
sqlite>

我已经启动了很多使 select/insert/delete 的进程,如果我不使用 sqlite-command 设置这个值,我有时会得到:

sqlite> select * from items where code like '%30';
Error: database is locked
sqlite> 

那么 .timeout 的默认值是多少?

在 Perl 5.10 程序中,有时我也会遇到此错误,尽管默认值似乎是 30.000(所以 30 秒,未记录)。
程序是否真的在这个错误之前等待了 30 秒?如果是,这看起来很疯狂,即使许多其​​他进程在此数据库 运行

上,至少有一小会儿数据库是空闲的
my $dbh = DBI->connect($database,"","") or die "cannot connect $DBI::errstr";
my $to = $dbh->sqlite_busy_timeout(); # $to get the value 30000

谢谢!

DBD::Sqlite 的默认忙碌超时在 dbdimp.h 中定义为 30000 毫秒。您可以使用 $dbh->sqlite_busy_timeout($ms);.

更改它

sqlite3 命令行 shell 具有正常的 Sqlite 默认值 0;也就是说,没有超时。如果数据库被锁定,它会立即出错。您可以使用 .timeout mspragma busy_timeout=ms;.

更改它

超时有效 as follows:

The handler will sleep multiple times until at least "ms" milliseconds of sleeping have accumulated. After at least "ms" milliseconds of sleeping, the handler returns 0 which causes sqlite3_step() to return SQLITE_BUSY.

如果即使有 30 秒的超时,您仍然遇到繁忙的数据库错误,您只是不走运,因为尝试获取锁的时间是在一个频繁使用的数据库文件上进行的(或者某些东西是 运行 真的查询慢)。如果尚未使用它,您可能会查看 WAL mode