Frequent Database Corruptions / Database Code

Toni's Avatar


14 Jan, 2020 09:21 PM


I frequently experience database corruptions for no real reason (eg. after pressing the Escape key while in the card browser), which has become a major pain in the behind for me. These now happen usually several times a day, even though I only edit my Anki database on one computer, and currently - due to this problem - refrain from syncing. But looking into the code, which seems to use plain DBAPI, and in the vein of having generally safer and better tested code, I consider trying to hack on Anki with the goal of porting the database logic to SQLAlchemy's declarative, which is battle-tested and gives high-level abstractions and integrity checks, amongst other niceties. I hope that this would make Anki quite a bit more robust, instead of the file on disk, which is a bit unwieldy.

What's your opinion?


  1. Support Staff 1 Posted by Damien Elmes on 14 Jan, 2020 10:36 PM

    Damien Elmes's Avatar

    Anki moved away from SQLAlchemy years ago as it had a measurable impact on performance. What exactly are the errors you're getting?

  2. 2 Posted by Toni on 14 Jan, 2020 10:55 PM

    Toni's Avatar

    I get lots of database corruption errors, which I have not yet debugged, and I have also not kept the myriad of tracebacks, but they frequently involve the equivalent of null pointer dereferences, and occur on many, many occasions. Also, when they occur, the only way to actually quit Anki to run the database check upon restart, is to kill the Python process, because inside Anki, it is no longer possible to quit. But if you can leave the thread open, I'll post some tracebacks tne next time around. Shouldn't take too long.

    Apart from that, computers have become much more beefy in the last few years. Anki sometimes runs with quite acceptable speed on a 10 year old computer of mine, but not having to repair the database so often would be a massive speedup for me in any case.

  3. Support Staff 3 Posted by Damien Elmes on 14 Jan, 2020 11:29 PM

    Damien Elmes's Avatar

    null pointer deferences sound like you're using broken libraries or modifying the database file externally (by putting it in a synced folder for example). They are not something you should see under normal use, and not something moving to SQLAlchemy would change, as it is simply a layer on top of the database library Anki is already using.

    You could try the packaged versions on the Anki website to see if the issue is with your system's sqlite libraries.

  4. Support Staff 4 Posted by Damien Elmes on 15 Jan, 2020 12:09 AM

    Damien Elmes's Avatar

    Actually, ignore that - sqlite is dynamically linked in the Linux builds, so your system version will still be picked up.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac