当插入〜5000行时,核心数据sqlite-wal文件获得MASSIVE(> 7GB) [英] Core Data sqlite-wal file gets MASSIVE (>7GB) when inserting ~5000 rows

查看:171
本文介绍了当插入〜5000行时,核心数据sqlite-wal文件获得MASSIVE(> 7GB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将数据导入Core Data,发现保存操作很慢。使用iOS模拟器,我看到sqlite-wal文件增长和增长,直到它的大小超过7GB。

I'm importing data into Core Data and find that the save operation is slow. Using the iOS simulator, I watch the sqlite-wal file grow and grow until its over 7GB in size.

我导入约5000记录约10个字段。这不是很多数据。

I'm importing approx 5000 records with about 10 fields. This isn't a lot of data.

我插入的每个对象都与其他对象(共6个关系)有一对一的关系。所有这些记录合并等于小于20个字段。没有图像或任何二进制数据或任何我可以看到,这将证明为什么WAL文件的结果大小是如此巨大。

Each object I'm inserting has a to-one relation to various other objects (6 relations total). All of those records combined equal less than 20 fields. There are no images or any binary data or anything that I can see that would justify why the resulting size of the WAL file is so huge.

我阅读sqlite文档描述wal文件和我没有看到这怎么可能发生。源数据不超过50 MB。

I read the sqlite docs describing the wal file and I don't see how this can happen. The source data isn't more than 50 MB.

我的应用程序是多线程的。
我在执行导入的后台线程中创建一个受管对象上下文(创建并保存核心数据对象)。

My app is multi-threaded. I create a managed object context in the background thread that performs the import (creates and saves the core data objects).

在这里不写代码,有人遇到这个吗?任何人都有一个想法我应该检查什么。代码不是超级简单,所有的部分都需要时间来输入,所以让我们从一般的想法开始。

Without writing the code out here, has anyone encountered this? Anyone have a thought on what I should be checking. The code isn't super simple and all the parts would take time to input here so lets start with general ideas.

我会给任何谁让我进入正确的方向。

I'll credit anyone who gets me going in the right direction.

额外的信息:


  • 对于上下文,因为我不需要(我认为它是零,默认情况下iOS,但我明确设置为nil)。

  • 在整个循环完成后,所有管理对象都在ram中(ram高达100 MB btw),我才调用save。

  • 核心数据对象的循环和创建只需要5秒左右。

推荐答案

这似乎是我的注释尝试使用旧的回滚(DELETE)日志模式而不是WAL日志模式解决问题。注意,使用WAL日志模式时,似乎存在一系列问题,包括以下内容:

It seems my comment to try using the old rollback(DELETE) journal mode rather than WAL journal mode fixed the problem. NOTE that there seem to be a range of problems when using WAL journal mode including the following:


  • 此问题

  • 使用migratePersistentStore API时数据库迁移的问题

  • 轻量级迁移问题

也许我们应该开始一个核心数据WAL问题页面,并得到一个完整的列表,并要求苹果修复这些错误。

Perhaps we should start a Core Data WAL problems page and get a comprehensive list and ask Apple to fix the bugs.

请注意,OS X 10.9和iOS 7现在使用WAL模式。要更改此背景,请添加以下选项

Note that the default mode under OS X 10.9 and iOS 7 now uses WAL mode. To change this back add the following option

@{ NSSQLitePragmaOptions : @{ @"journal_mode" : @"DELETE" } }

这篇关于当插入〜5000行时,核心数据sqlite-wal文件获得MASSIVE(> 7GB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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