SQLite3 .backup 和 .dump 命令会锁定数据库吗? [英] Do the SQLite3 .backup and .dump commands lock the database?

查看:23
本文介绍了SQLite3 .backup 和 .dump 命令会锁定数据库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能找到的关于 .backup.dump 的唯一文档是 .help 显示的文档:

The only documentation I've been able to find about .backup and .dump is the one shown by .help:

.backup ?DB? FILE      Backup DB (default "main") to FILE
.dump ?TABLE? ...      Dump the database in an SQL text format
                         If TABLE specified, only dump tables matching
                         LIKE pattern TABLE.

最大的问题是:这两个命令在复制/转储之前是否锁定了数据库?备份是否一致?

The big question is: do both these commands lock the database before copying/dumping? Is the backup consistent?

这个答案有一些关于 .backup 的信息,但是否有任何权威文档那个?(.dump 怎么样?)我在 SQLite 的文档中唯一能找到的是在线备份 API",但我对 API 不感兴趣,我只想备份数据库.

This answer has some information on .backup, but is there any authoritative documentation for that? (And what about .dump?) The only thing I've been able to find in the SQLite's documentation is the "Online Backup API", but I'm not interested in an API, I just want to backup the database.

推荐答案

.dump 命令只是在事务中使用一堆 SELECT 语句读取整个数据库.该事务自动锁定数据库进行写入,但允许并发读取.

The .dump command just reads the entire database with a bunch of SELECT statements, inside a transaction. This transaction automatically locks the database for writing, but allows concurrent reads.

.backup 命令与 SQL 无关;它将数据库页面直接复制到一个新文件中.所有页面读取都通过正常机制访问数据库文件,并封装在事务中.当使用多个sqlite3_backup_step()调用时,事务结束以允许其他连接访问数据库,但检测到任何更改,在这种情况下,整个备份将自动重新启动.

The .backup commands does not bother with SQL; it copies the database pages directly to a new file. All page reads go through the normal mechanism to access the database file, and are wrapped inside a transaction. When using multiple sqlite3_backup_step() calls, the transaction is ended to allow other connections to access the DB, but any changes are detected, and in this case, the entire backup is automatically restarted.

这篇关于SQLite3 .backup 和 .dump 命令会锁定数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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