python保存在内存中sqlite [英] python save in memory sqlite

查看:33
本文介绍了python保存在内存中sqlite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将我的内存中的 sqlite 数据库保存到硬盘?如果可能的话,一些 python 代码会很棒.

Is it possible to save my in-memory sqlite database to hard disk? If it is possible, some python code would be awesome.

提前致谢.

我通过使用 apsw 成功完成了这项任务.它就像一个魅力.感谢您的贡献.

I succeeded this task by using apsw . It works like a charm. Thanks for your contribution.

推荐答案

(披露:我是 APSW 作者)

(Disclosure: I am the APSW author)

制作数据库二进制副本的唯一安全方法是使用作为 SQLite 一部分并由 APSW 公开的备份 API.这在排序、锁定和并发方面做正确的事情.

The only safe way to make a binary copy of a database is to use the backup API that is part of SQLite and is exposed by APSW. This does the right thing with ordering, locking and concurrency.

要制作数据库的 SQL(文本)副本,请使用 APSW shell,其中包含非常完整的 .dump 实现.您可以使用 cursor.execute() 将 SQL 转回数据库.

To make a SQL (text) copy of the a database then use the APSW shell which includes a .dump implementation that is very complete. You can use cursor.execute() to turn the SQL back into a database.

在最近的平台上,您不太可能看到内存数据库和磁盘数据库之间的太大区别(假设您关闭了磁盘的日志功能),因为操作系统维护文件系统缓存.较旧的操作系统(如 Windows XP)确实有一个默认配置,即无论您有多少 RAM,都只使用 10MB 内存用于文件缓存.

On recent platforms you are unlikely to see much of a difference between a memory database and a disk one (assuming you turned journaling off for the disk) as the operating system maintains a file system cache. Older operating systems like Windows XP did have a default configuration of only using 10MB of memory for file cache no matter how much RAM you have.

这篇关于python保存在内存中sqlite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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