Performance tip of the day

If your Firefox, like mine, insists on doing huge amounts of I/O when closing, as well as acts slow when using the awesomebar, try the following (close down Firefox completely first):

for f in ~/.mozilla/firefox/*/*.sqlite; do sqlite3 $f 'VACUUM;'; done

It’s harmless, no data will be lost: it compacts your SQLite databases. Noticable gains for me.

This entry was posted in Uncategorized. Bookmark the permalink.

35 Responses to Performance tip of the day

  1. Qball says:

    Perfect! een wereld van verschil.

  2. Chris says:

    Big thanks. Seems to work.

    Just noticed: I set history to 10 days about a month ago because awsomebar was soooo slow but it still keeps all my history in the database.

  3. Aquarion says:

    For OS X, this is:

    for f in ~/Library/Application Support/Firefox/Profiles/*/*.sqlite; do sqlite3 “$f” ‘VACUUM;’; done

  4. Dav Glass says:

    You can do this on OSX:

    cd ~/Library/Application Support/Firefox/Profiles/
    for f in */*.sqlite; do sqlite3 $f ‘VACUUM;’; done

  5. Stoffe says:

    Maybe a bug should be filed to ask Mozilla to set the database(s) to auto-vacuum, or maybe this should be done on shutdown at least.

  6. Ulisse says:

    Thanks a lot, my awesomebar is really quickier now!

  7. michele says:

    Yeah! tip of the year!!! :-)

    Finally Firefox starts and stops in reasonable times!

    Thanks a lot!

  8. Stefano says:

    It is also useful for liferea, for sqlite files in ~/.liferea-1.4/mozilla/liferea/ . Thanks!

  9. Ian McKellar says:

    This is the problem with using SQLite in desktop apps – I need to be my own frickin’ DBA!

  10. Paul says:

    Finally – I have a responsive Firefox again. Thanks!

  11. usar says:

    didn’t work for me on Ubuntu 8.10. I get a string of:
    Unable to open database “~/.mozilla/firefox/432n677u.default”: unable to open database file. Same thing when I sudo su to log in as root and run it.

  12. RubenV says:

    @usar: Double check that you used the right command, looks like there’s a piece of the matching pattern missing.

  13. Aaron Strontsman says:

    Awesomestest! Thank you.

  14. mike says:

    SQL error: constraint failed

  15. Richard Rebel says:

    A general purpose shell gotcha safe version that will do all your sqlite files:

    find ~ -name ‘*.sqlite’ -exec sqlite3 ‘{}’ ‘VACUUM;’ ;

    Works on directories containing spaces and is safe fro cronjob use.

  16. rys says:

    What about windows? How do we get a command line for Mysql lite??

  17. Artem Vakhitov says:

    How do I do that on Windows? I too want my Firefox not freeze when using the not-so-awesomebar.

  18. RubenV says:

    @rys, @Artem: Unfortunately, I don’t have a windows computer (I’m a pure Linux user), so I can’t help you out there. If someone does know how to do it: let us know!

  19. Kimble says:

    Nice! This helped a lot!
    Thanks

  20. Tom says:

    @Aquarion,Dav Glass: Thnx! Unfortunately you forgot escaping the spaces, so the working commands are:

    for f in ~/Library/Application Support/Firefox/Profiles/*/*.sqlite; do sqlite3 “$f” ‘VACUUM;’; done

    and

    cd ~/Library/Application Support/Firefox/Profiles/
    for f in */*.sqlite; do sqlite3 $f ‘VACUUM;’; done

    @Richard Rebel: Nice tip, there are indeed other applications who suffer from this. On OS X Tiger, example number 1 being Apple Mail..

  21. RubenV says:

    @Tom: Unfortunately, you forgot quoting as well: Application Support contains a space, which won’t work. So substitute it for Application\\ Support.

  22. Delta says:

    I couldn’t get
    find ~ -name ‘*.sqlite’ -exec sqlite3 ‘{}’ ‘VACUUM;’ ;

    to run, so I had to add a backslash ( ‘\\’ ) to the last semicolon ( ‘;’ ):
    find ~ -name ‘*.sqlite’ -exec sqlite3 ‘{}’ ‘VACUUM;’ ;

    Nice tip, though; thanks!

  23. Tom says:

    Bummer, I did copy-paste the wrong snippet! Thnx for correcting my corrections ;-)

  24. Peter says:

    @Richard Rebel

    The problem is running from a cronjob is that you probably want to make sure the appropriate applications are closed first.

    It would also help speed up the new summaries in evolution I think.

    Also I believe this is on Mozilla’s ToDo list but they had issues with doing it automatically that are yet to be resolved.

  25. Roshan says:

    Holy Jesus! That was one hell of an improvement! Thanks!

  26. Not a complete windows HOWTO but this will get you there:

    1) Download the Precompiled Binaries For Windows http://www.sqlite.org/download.html.

    2) I extracted the file to C:bin.

    3) Change into the directory containing the .sqlite files. Example: cd C:Documents and SettingsrootApplication DateMozillaFirefoxl89ueo7d.default

    4) Get a before shot: dir *.sqlite

    5) Run the VACUUM: for %f in (*.sqlite) do C:binsqlite3.exe %f “VACUUM;”

    6) Get an after shot: dir *sqlite

    My results:
    BEFORE
    11/25/2008 01:39 PM 7,168 content-prefs.sqlite
    01/04/2009 08:15 PM 178,176 cookies.sqlite
    01/06/2009 11:54 PM 744,448 downloads.sqlite
    01/06/2009 11:54 PM 576,512 formhistory.sqlite
    01/02/2009 05:14 PM 191,488 kongregate.sqlite
    11/03/2008 02:37 PM 2,048 permissions.sqlite
    01/06/2009 11:54 PM 50,679,808 places.sqlite
    08/06/2008 01:11 PM 2,048 search.sqlite
    12/30/2008 05:43 PM 4,096 webappsstore.sqlite

    AFTER
    01/07/2009 12:38 AM 7,168 content-prefs.sqlite
    01/07/2009 12:38 AM 99,328 cookies.sqlite
    01/07/2009 12:38 AM 389,120 downloads.sqlite
    01/07/2009 12:38 AM 558,080 formhistory.sqlite
    01/07/2009 12:38 AM 186,368 kongregate.sqlite
    01/07/2009 12:38 AM 2,048 permissions.sqlite
    01/07/2009 12:39 AM 42,889,216 places.sqlite
    01/07/2009 12:39 AM 2,048 search.sqlite
    01/07/2009 12:39 AM 2,048 webappsstore.sqlite

  27. jshare says:

    For windows:
    * get sqlite3 from here:
    * http://www.sqlite.org/sqlite-3_6_7.zip
    * http://www.sqlite.org/sqlitedll-3_6_7.zip
    * unzip them both into c:windowssystem32
    * cd to your profile directory (there may be an easier way to specify this from the commandline, but I don’t know cmd globbing that well)
    * for %f in (*sqlite) do sqlite3 %f “VACUUM;”
    * note: quotes instead of apostrophes

  28. Lee Willis says:

    On Windows you’ll probably have to install sqlite3 (http://www.sqlite.org/download.html)

    Then (Assuming that the binary is in your Windows path) you can change to the Mozilla Profile directory

    C:Documents and SettingsApplication DataMozillaFirefoxProfiles.default/

    and run:

    sqlite3 places.sqlite “VACUUM;”

    Replacing places.sqlite with the file you want to compact – sorry I’m not familiar enough with Windows scripting to work out how to automatically do it for every file – for me the only large sqlite files were:
    - places.sqlite
    - urlclassifier2.sqlite

  29. Pacho Ramos says:

    To Richard Rebel:

    About adding it to a cron job, Should script check if any firefox instance is running? Would it break “something” if it’s run while firefox is running?

    Thanks for information

  30. Jeremy says:

    sqlite has correct locking and database semantics, so you should be able to do this with firefox running.

  31. Pacho Ramos says:

    OK, thanks for the info :-)

  32. Bill says:

    There should be an addon that does this once a month or so, as a stopgap before it’s added into Firefox (or Gecko) proper.

  33. SchAmane says:

    WOW, thanks for this tip!

  34. @Jeremy

    Not sure about sqlite having correct locking and database semantics, but you definitely get an error if Firefox is running: “SQL error: database is locked”.

    Got that on both Linux and Mac OS X.

  35. Marius: Jeremy’s tip about it running this command with Firefox running still is sorta valid; it won’t optimize Firefox’s databases, but it won’t harm them either.

    So if you’re setting up a cron job, it will do its thing on whichever databases are available. It’s not the kind of thing you’d need to run every day, so just make sure you have Firefox (or your other apps) closed at least sometimes. ;)

    Also, this wouldn’t pick up any sqlite databases that don’t end in “.sqlite”, so there could be further gains to be made here. For example, I ran this on Banshee’s database (~/.config/banshee-1/banshee.db) and found a decent performance gain in the application.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>