简体   繁体   English

SQLite用完内存而不会引发异常

[英]SQLite running out of memory without throwing exception

I have a simple C# application reading CSV files into an SQLite database. 我有一个简单的C#应用​​程序,将CSV文件读入SQLite数据库。

When the data has been read (the database file is approximately 5GB at this time), I create an index on the single table that contains all the data. 读取数据后(此时数据库文件约为5GB),我在包含所有数据的单个表上创建了一个索引。

CREATE INDEX index_name ON table_name(col_a, col_b ASC)

I can then see the following error message in the Visual Studio debug output window: 然后,我可以在Visual Studio调试输出窗口中看到以下错误消息:

SQLite error (6154): os_win.c:41445: (8) winMapfile2() - Not enough storage is available to process this command.

The error message repeats itself a couple of hundred times during a few seconds while creating the index. 在创建索引的过程中,错误消息在几秒钟内重复了数百次。

The SQLite documentation says the following: SQLite文档说明以下内容:

(6154) SQLITE_IOERR_MMAP (6154)SQLITE_IOERR_MMAP
The SQLITE_IOERR_MMAP error code is an extended error code for SQLITE_IOERR indicating an I/O error within the xFetch or xUnfetch methods on the sqlite3_io_methods object while trying to map or unmap part of the database file into the process address space. SQLITE_IOERR_MMAP错误代码是SQLITE_IOERR的扩展错误代码,指示尝试将数据库文件的一部分映射或取消映射到进程地址空间时,sqlite3_io_methods对象上xFetch或xUnfetch方法内的I / O错误。

My hard drive still has about 30GB left, the process is only using about 300MB of memory while running the command, and there is at least 30% available physical memory on the computer, so I'm not sure why it happens at all. 我的硬盘驱动器上还剩余约30GB的空间,运行该命令时该过程仅使用了约300MB的内存,并且计算机上至少有30%的可用物理内存,因此我不确定为什么会发生这种情况。

No exceptions are being thrown, it is only printed to the debug console. 不会引发任何异常,它只会打印到调试控制台。 The index seems to be created properly in the database. 索引似乎已在数据库中正确创建。 Does that mean that the error message isn't harmful? 这是否意味着错误消息没有危害? Can I safely ignore it? 我可以放心地忽略它吗? Can I make it throw an actual exception if something goes wrong? 如果出现问题,我可以使其抛出实际异常吗? I find it kind of scary that my databases may be corrupt. 我发现我的数据库可能已损坏,这很可怕。

MMAP is just an optimization. MMAP只是一种优化。 If it fails, SQLite falls back to using normal FileRead() calls. 如果失败,SQLite将退回到使用常规FileRead()调用。

That you don't have enough address space to map a 5 GB file is probably OK on your machine. 您没有足够的地址空间来映射5 GB的文件在您的计算机上可能是可以的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM