且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQLite 数据库的大小有限制吗?

更新时间:2023-11-25 15:41:16

这很容易从 实施限制页面:

一个 SQLite 数据库文件被组织成页面.每个页面的大小是 512 和 SQLITE_MAX_PAGE_SIZE 之间的 2 的幂.SQLITE_MAX_PAGE_SIZE 的默认值为 32768.

An SQLite database file is organized as pages. The size of each page is a power of 2 between 512 and SQLITE_MAX_PAGE_SIZE. The default value for SQLITE_MAX_PAGE_SIZE is 32768.

...

SQLITE_MAX_PAGE_COUNT 参数通常设置为 1073741823,是单个数据库文件中允许的最大页数.尝试插入新数据会导致数据库文件变得比这更大将返回 SQLITE_FULL.

The SQLITE_MAX_PAGE_COUNT parameter, which is normally set to 1073741823, is the maximum number of pages allowed in a single database file. An attempt to insert new data that would cause the database file to grow larger than this will return SQLITE_FULL.

所以我们有 32768 * 1073741823,也就是 35,184,372,056,064(35 万亿 个字节)!

So we have 32768 * 1073741823, which is 35,184,372,056,064 (35 trillion bytes)!

您可以修改源代码中的 SQLITE_MAX_PAGE_COUNTSQLITE_MAX_PAGE_SIZE,但这当然需要为您的应用程序自定义构建 SQLite.据我所知,除了在编译时之外,没有办法以编程方式设置限制(但我很乐意被证明是错误的).

You can modify SQLITE_MAX_PAGE_COUNT or SQLITE_MAX_PAGE_SIZE in the source, but this of course will require a custom build of SQLite for your application. As far as I'm aware, there's no way to set a limit programmatically other than at compile time (but I'd be happy to be proven wrong).