I use Zotero to manage my references and have for decades since it was first developed. I’m a huge fan and teach all my students how to use it.
But I also don’t follow one of the programmers’ recommendations on where to store my Zotero database. As soon as I install Zotero, I change the location where everything is stored to a folder where I have my main database and that is in a Dropbox folder that gets synced across all of my computers. Every time I do that, the software pops up a warning saying I shouldn’t. But I want my Zotero database on all of my computers. I know I could sync with the Zotero option and probably should, but I don’t. As a result, every so often (every couple of years), I get a message that my Zotero sqlite file has been corrupted. It could be because I’m storing it in Dropbox or it could just be that my database is very large and it runs into issues. Not sure. But this just happened again, and I was able to fix it using some pretty basic commands on Linux. Here’s what I did.
First, software versions for people reading this in the future: I’m running Zotero 7.0.15 (64-bit) on Kubuntu 24.04.
Open a console or shell and navigate to where your Zotero sqlite file is stored. For me, that was this command:
cd /home/ryan/Dropbox/Ryan/zotero/database-master/
Once there, here’s the first command to run (after you make sure that Zotero is closed and not running, or you’ll get an error):
sqlite3 zotero.sqlite ".dump" > zotero_dump.sql
That command pulls everything out of your existing sqlite database and dumps it into a backup. Given how big my database is (over 700 megabytes), it took a few minutes to run. When it was done, I used the following command to make a backup (smart to always make a backup):
mv zotero.sqlite zotero.sqlite.broken
That command “moves” (mv) the existing database to a new database that now has the file extension “.broken”. In other words, it just made a backup that will not get in the way of creating a new database because of the file extension. If the next part doesn’t work or you have an issue, you can always just change the file extension of the backup by deleting “.broken” and you haven’t lost anything.
The final command rebuilds your database from the dump:
sqlite3 zotero.sqlite < zotero_dump.sql
This took a few minutes to run as well and showed me where the errors were in the previous database. I got the following three errors:
- Runtime error near line 846887: UNIQUE constraint failed: fulltextWords.word (19)
- Runtime error near line 846983: UNIQUE constraint failed: fulltextWords.word (19)
- Runtime error near line 5781458: UNIQUE constraint failed: fulltextItemWords.wordID, fulltextItemWords.itemID (19)
I don’t know exactly what those mean, but my guess is that Zotero was trying to index some of the items in my database by searching through the full text. Somewhere in that process – either because my database was being synchronized by Dropbox or due to something else – there was a problem, and that led to an issue with the database. Presumably, when the new version was being created, those errors were dropped. If the only errors I had were full-text indexing errors, I think I’m good.
Anyway, this is a quick and easy way to repair your Zotero sqlite database on Linux.
Leave a Reply