66

I'm preparing an update for a Core Data based app for fixes with iOS 7. I use Xcode 5 and iOS 7 SDK GM. However I realized a different behavior of the persistent store (which is a UIManagedDocument): Prior to iOS 7 builds there was only one file persistentStore in the documents folder (sometimes there was a second one persistentStore-journal).

In iOS 7 builds (clean installation) there are now three files for the persistent store:

  • persistentStore
  • persistentStore-wal and
  • persistentStore-shm

Did Apple change the journal mode by default to WAL now? I wonder if there is an impact on my app (think of users how update from the last version)? Would it be best to disable WAL - and if so, how can I do this with iOS 7/UIManagedDocument?

FrankZp
  • 1,996
  • 3
  • 21
  • 36
  • 2
    Perhaps have a look at the "What’s New in Core Data and iCloud" session from WWDC 2013. You can download the PDF file from https://developer.apple.com/wwdc/videos/. Apple changed the default journaling mode for the SQLite file from "rollback" to "write-ahead logging". – Martin R Sep 18 '13 at 11:03

1 Answers1

96

Yes, Apple have changed the default journal mode to WAL for iOS7. You can specify the journal mode by adding the NSSQLitePragmasOption to the options when calling addPersistentStoreWithType:configuration:url:options:error. E.g. to set the previous default mode of DELETE:

NSDictionary *options = @{ NSSQLitePragmasOption : @{@"journal_mode" : @"DELETE"} };

In my experience WAL gives better performance, but also see this post:

iOS CoreData - are there any disadvantages to enabling sqlite WAL / Write-Ahead Logging

Community
  • 1
  • 1
Andy Etheridge
  • 1,253
  • 9
  • 6
  • 4
    Hey @Andy, there's slight spelling mistake in your code. It should read @"journal_mode". – ajmccall Sep 24 '13 at 16:54
  • 1
    @ajmccall I took care of the typo in `journal_mode` check out http://sqlite.org/pragma.html for all options. – Chris Wagner Oct 03 '13 at 23:22
  • 3
    We have an app that users started to complain they lost their data when they updated to the latest version, which was compiled for iOS 7. Changing the journal mode back to DELETE fixed our problem. – Rickster Dec 06 '13 at 01:29
  • 5
    This is a horrible way to roll this feature out. Apple should have known better than to auto enable this feature. Now to create a backup of a database, users have to have both files.. I have had hundred of user loose data when they restored their ios devices from backups after a ios7 update only to find that the WAL file was missing so all the data since moving to ios 7 is gone... simply upgrading a device to ios7 changes the way all the app store their data. Who thought this was a good "default" – J3RM Jan 27 '14 at 22:54
  • 1
    Add me to the list of burned devs who also didn't notice this issue in advance. The DELETE option also worked for me. – Bek Feb 12 '14 at 20:02
  • @Andy Etheridge i am already using like this, NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; Now if i replace this with NSDictionary *options = @{ NSSQLitePragmasOption : @{@"journal_mode" : @"DELETE"} }; If this works fine or any error will comes in the future? – Maniganda saravanan Mar 05 '14 at 13:47
  • Core Data on Mavericks will ignore the setting after a while, when it seems the Persistent Store reloads the store automatically. – Conor Jun 05 '14 at 15:56