Skip to content

Sqlite: Create databases with journal_mode=WAL #14059

Closed

Description

@bricelam

When EF creates SQLite databases (via EnsureCreated or Migrations), we should consider setting the journaling mode to write-ahead logging.

Pros:

  • Faster
  • Better concurrency (less locking)

Cons:

  • Not for databases accessed via a network file share

Activity

  1. bricelam commented on Dec 1, 2018

    @bricelam
    ContributorAuthor

    @ericsink Any reason not to? (in EF Core, not the ADO.NET provider)

  2. ericsink commented on Dec 1, 2018

    @ericsink
    Contributor

    IMO, WAL mode in general is better for ~98% of cases.

    #ifdef QUIBBLE
    Note that it is not universally true that WAL mode is faster. In fact, in some cases involving reads, it's slower: https://www.sqlite.org/wal.html#performance_considerations
    #endif

    But in general, using WAL mode is good, and will probably be the right choice for most users. I use WAL mode all the time on all of my projects.

    That said, a wrapper that automatically sets WAL mode can be a problem. The sqlite-net library recently made a change to use WAL mode all the time, and it has caused a number of problems.

    See praeclarum/sqlite-net#765 for more info.

    If you make this change to EF Core, it will probably benefit most users, but it will very likely cause trouble for somebody.

    I would agree that making this kind of change at a higher abstraction layer (like EF Core) is much more appropriate to consider than at lower layers (like the ADO.NET provider).

  3. bricelam commented on Dec 1, 2018

    @bricelam
    ContributorAuthor

    I’d like to mitigate the risk by only setting it on new databases (not for every connection). If you find out that you don’t want it, you can just send the PRAGMA in a migration or something to disable it.

  4. added this to the 3.0.0 milestone on Dec 3, 2018
  5. effpath999 commented on Jan 19, 2019

    @effpath999

    Please, if you do, give the developers a working opportunity to opt out. I have an app which use sqlite-net and their defaulting to WAL in the connection constructor in the latest version completely broke my export data functionality, which relayed on the fact that all the data was in the sqlite file, which is no more true when WAL is enabled. Tried to invoke PRAGMA wal_checkpoint(FULL) before exporting, but this only mitigate the issue, in that most often than not the most recent data are not copied from the -wal file to the sqlite one.
    Also, closing the connection does not force the -wal file to be emptied (maybe a bug in sqlite-net implementation, I don't know).
    Disabling WAL with pragma journal_mode does not work either consistently (that is: almost never).
    If someone knows a proper way to export data when WAL is enabled I would be glad to know, but still, I think that is better to have the choice to opt out at the constructor level.

  6. added a commit that references this issue on Mar 25, 2019
    8dc04e6
  7. modified the milestones: 3.0.0, on Apr 15, 2019
  8. modified the milestones: , 3.0.0 on Nov 11, 2019
  9. ahdung commented on Mar 24, 2023

    @ahdung

    So how to disable WAL today?

  10. bricelam commented on Mar 24, 2023

    @bricelam
    ContributorAuthor

    @ahdung After the database is created by EF, you can turn off WAL using by ececuting this SQL on it:

    PRAGMA journal_mode = 'delete';
  11. ahdung commented on Mar 25, 2023

    @ahdung

    @bricelam Thank you very much.

  12. added theissue type on Jun 15, 2025
  13. dgxhubbard commented on Aug 7, 2025

    @dgxhubbard
  14. roji commented on Aug 8, 2025

    @roji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions