Vacuum Firefox databases for better performance, now with no restart
Posted by Percy Cabello on August 22nd, 2009 • Tags:
ShareThis

A few months ago, I posted how to improve Firefox performance by defragmenting its database files executing SQLite VACUUM command. The only con was that it required a Firefox restart to execute the command.

Thanks to Mozilla’s Jeremy Orem, we have now learned it can be done from within Firefox in two short steps:

  • Open the Error Console: Tools menu/Error Console
  • In the Code text box paste this (it’s a single line):
    Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL("VACUUM");
  • Press Evaluate. All the UI will freeze for a few seconds while databases are VACUUMed

Vacuuming Firefox databases from the Error Console

Note however that the procedure optimizes the Places database only, but this is precisely where you will get the most significant performance improvements.

Comments in Jeremy’s blog post point to the open bug on the issue and plans to include this optimization by default, and Vacuum Places, an (experimental) add-on by Revertron that does just this.

http://blog.mozilla.com/oremj/2009/08/20/speedup-firefox-with-vacuum/
Comments
David Naylor said on August 22, 2009, 1:18 am:

Great tip. Thanks! Didn’t know this could be done from inside Firefox.

Reply

El Guru said on August 22, 2009, 1:18 am:

I just tried this and got an error about ‘an illegal character’….

Reply

Arneh said on August 22, 2009, 1:59 am:

El Guru, it’s the last two quotation marks, try:

Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL(“VACUUM”);

Reply

Arneh said on August 22, 2009, 2:01 am:

Hmm, it didn’t come out correctly in my altered paste above. Just replace the last two italic quotation marks with regular ones.

Reply

Greg said on August 22, 2009, 2:39 am:

Also getting an error about ‘an illegal character’

Reply

Clochix said on August 22, 2009, 3:14 am:

Thanks for sharing this tip.

@El Guru : just replace the curved quotes (”) around VACUUM with typewriters quotes (“).

The nsPIPlacesDatabase interface seems to be new in FF 3.5, so it probably won’t work with FF 3.0.x. Time to update ;)

Reply

inselaffe said on August 22, 2009, 3:58 am:

i get the ‘illegal character’ message too…

Reply

FND said on August 22, 2009, 4:01 am:

El Guru: Replace the pretty quotes around VACUUM with regular double quotes.

Reply

TnS said on August 22, 2009, 4:58 am:

El Guru: Because the typographic quotation marks around VACUUM. Here is the correct:

Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL(“VACUUM”);

Reply

TnS said on August 22, 2009, 5:00 am:

Got auto converted… After copy&pasting replace them manually. :)

Reply

Philipp said on August 22, 2009, 5:01 am:

@El Guru:
I got the same error but found the solution. You have to replace the ”-characters around VACUUM (at the end) with normal “-characters. Hope this works for you ;)

Reply

Stan said on August 22, 2009, 5:11 am:

Percy, the text from the main article is overlapping the links and history columns.

Reply

Percy Cabello replied on August 22nd, 2009, 10:32 am:

Yeah, sorry about that. It’s fixed now and with the correct characters. Thanks for the head up all.

Ray R. said on August 22, 2009, 7:53 am:

If you have the Console2 extension installed, the text box to the left of the “Evaluate” button is not IDed. Is this box the same as the “Code” box cited above?

Reply

leandro said on August 22, 2009, 1:08 pm:

Good post! My places.sqlite went from 23MB to 3,75MB !!!

Reply

level said on August 22, 2009, 11:54 pm:

Vacuum Places :: Add-ons for Firefox
https://addons.mozilla.org/en-US/firefox/addon/13824

Reply

Zen @ ASUS Eee PC said on August 24, 2009, 7:47 pm:

Nothing seems to be happening to my browser. Any ideas??

Reply

Cirus said on August 25, 2009, 3:15 am:

https://addons.mozilla.org/en-US/statistics/addon/13878

A polished version of Vacuum Places, with automatic cleaning, periodic reminder and i18n

Reply

Ray R. replied on August 31st, 2009, 7:15 am:

Cirus,

I am getting a “You do not have access error” when trying to follow your provided link. Is there another way to get to that add-on?

Toby said on August 25, 2009, 4:21 am:

I get “uncaught exception”:

Error: uncaught exception: [Exception... "Component returned failure code: 0x80570018 (NS_ERROR_XPC_BAD_IID) [nsIJSCID.getService]” nsresult: “0×80570018 (NS_ERROR_XPC_BAD_IID)” location: “JS frame :: javascript:%20Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL(“VACUUM”); :: :: line 1″ data: no]

Reply

Rob T. said on August 25, 2009, 10:16 am:

I’m getting the following exception when I try to run this.

Error: uncaught exception: [Exception... "Component returned failure code: 0x80570018 (NS_ERROR_XPC_BAD_IID) [nsIJSCID.getService]” nsresult: “0×80570018 (NS_ERROR_XPC_BAD_IID)” location: “JS frame :: javascript:%20Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL(“VACUUM”); :: :: line 1″ data: no]

I’ve checked that I’ve got normal quotes.

When I try to break it down, the error is being thrown from the getService
Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase)

What am I doing wrong?

Thanks,
–Rob

Reply

Andrew Z said on August 25, 2009, 11:43 am:

Some people may find vacuuming easier to do with BleachBit. It’s simple clicking without any complex commands

Reply

MarsianMan said on August 25, 2009, 2:54 pm:

Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.executeSimpleSQL]” nsresult: “0×80004005 (NS_ERROR_FAILURE)” location: “JS frame :: javascript:%20Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL(“VACUUM”); :: :: line 1″ data: no]

running: Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL(“VACUUM”);

Reply

Matt said on August 26, 2009, 9:58 am:

Can this be adapted to work in Flock please?

Reply

Giulio said on August 26, 2009, 11:35 am:

Not working for me:

Error: uncaught exception: [Exception... "Component returned failure code: 0x80570018 (NS_ERROR_XPC_BAD_IID) [nsIJSCID.getService]” nsresult: “0×80570018 (NS_ERROR_XPC_BAD_IID)” location: “JS frame :: javascript:%20Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL(“VACUUM”); :: :: line 1″ data: no]

I’m running version 3.0.13 on Ubuntu Hardy Heron.

Reply

Giulio replied on August 26th, 2009, 4:23 pm:

EDIT: I just figured out that the trick only works with Firefox 3.5

Bob said on August 27, 2009, 2:28 am:

WooHoo!.
I put that code into a “Custombuttons²”-button for easy access, works great!

Reply

xoc said on August 30, 2009, 7:55 pm:

I get:

Error: uncaught exception: [Exception... "Component returned failure code: 0x80570018 (NS_ERROR_XPC_BAD_IID) [nsIJSCID.getService]” nsresult: “0×80570018 (NS_ERROR_XPC_BAD_IID)” location: “JS frame :: javascript:%20Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL(“VACUUM”); :: :: line 1″ data: no]

Reply

Giulio replied on September 1st, 2009, 4:24 pm:

Only works in FF3.5.
If yuo have a former version (3.0 or higher) you can use this howto to vacuum all the databases “manually”:
http://mozillalinks.org/wp/2009/07/vacuum-your-firefox-databases-for-better-performance/

Mohammad Khatib said on September 3, 2009, 4:32 pm:

Thanks! Keep the performance of Firefox up please!
This really helped!

Reply

Alan said on September 8, 2009, 5:14 am:

I get a “missing ; before command” error… !

Reply

Jawwad said on October 23, 2009, 6:52 am:

i paste this code in code bar >
Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL(“VACUUM”);

but nothing is happen after clicking Evaluate ?? why ?

Reply

Ray R. replied on October 23rd, 2009, 11:57 am:

I think all quotes need to be straight quotes. The quotes around VACUUM appear to be angled.

There are now add-ons that provide a nice user interface to vacuum Places. I use Vacuum Places Improved 1 available at https://addons.mozilla.org/en-US/firefox/addon/13878

nonpyrogenic said on November 28, 2009, 8:37 am:

you need this small application speedyfox.exe find it w/ searchengine

Reply

AbortRetry---> FFv3.6=EpicFail said on January 22, 2010, 6:06 pm:

Here’s the correct one, copy the ENTIRE LINE, paste into Error Console from Tools dropdown menu within Firefox:

Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL(“VACUUM”);

By the way, the above does NOT work with FireFox v3.6, it just sits there and does nothing, no error, no syntax issues, zip, just sits there, and in reply to the guy above, SpeedyFox does NOT shink your places file, it has nothing to do with this phishing database and all about MTU, browser chache and TCP tweakz, so your comment is OFF TOPIC.

Anyway, the latest build of FF v3.6 (available now from Mozilla) which I installed yesterday to WinVista as a test, now has a file called “urlclassifier3.sqlite” that has somehow inflated to 14.2 gigabytes?!? Anyone know how I might get that shrunken down to a more resonable size? This strange bloatfile is slowing down everything that is cool about FireFox.

It is located here: ~\AppData\Local\Mozilla\Firefox\Profiles\np147ohm.default

Traditionally, in FF v3.5 the “urlclassifier3.sqlite” never got any larger than 20-30 mb, it suddenly bloated itself like a cancerous biomass in my PC, and each time I close/open FF v3.6, it seems to expand by another gig or so, how is that possible?

For now, I’m going back to FireFox 3.5, more stable and without the baloon bloat plague affecting these critical files.

Reply

Andrew replied on January 23rd, 2010, 1:43 pm:

BleachBit vacuums Firefox 3.6.