データベースの再構築でFirefox3を軽くする

ふだん使っているFirefox3の動作が、だんだん重くなってきました。

Firefox3では、ライブラリとして動作するRDBMSであるSQLiteを使って、データの管理を行っています。例えばブックマークと履歴は、places.sqlite という、SQLiteで作られたデータベースのファイルで管理されています。ブックマークと履歴をひとつのデータベースで管理するわけですから、当然のごとく巨大なファイルになっていきます。

そこで、以下のページを参考にし、places.sqlite を再構築してファイルサイズを小さくします。

手順をまとめると、次のようになります。Mac OS X (Leopard) です。この処理を実行するには、SQLite 3がインストールされている必要があります (Mac OS X の場合は、最初からインストールされています)。

$ cd ~/Library/Application\ Support/Firefox/Profiles/(プロファイル名)
$ cp places.sqlite places.sqlite.bak
$ sqlite3 places.sqlite vacuum

SQLiteの公式ページでは、vacuumについて次のように説明しています。

When an object (table, index, or trigger) is dropped from the database, it leaves behind empty space. This makes the database file larger than it needs to be, but can speed up inserts. In time inserts and deletes can leave the database file structure fragmented, which slows down disk access to the database contents.


The VACUUM command cleans the main database by copying its contents to a temporary database file and reloading the original database file from the copy. This eliminates free pages, aligns table data to be contiguous, and otherwise cleans up the database file structure.

http://www.sqlite.org/lang_vacuum.html

"it leaves behind empty space" ですから、PostgreSQLと同じような感じなのですかね? いずれにせよ、places.sqlite に対して vacuumコマンドを実行すると、データベースを軽くできそうです。僕の場合はどうでしょうか?

$ ls -l places.sqlite*
35012608  1 29 19:28 places.sqlite
43298816  1 29 19:28 places.sqlite.bak

41.3MBが33.4MBまで減っています。効果があったようです。

では、使ってみてどうかというと、確かにかなり軽くなった気がします。いや、間違いなく軽くなりました!

...きちんと計測しなければなりませんね。軽量化には、インデックスを作成しなおすなど、ほかにもいろいろ方法があるようです。いずれ調べてみます。

また、この方法は、SQLiteが使われている他のアプリケーションにも応用できるようです。Movable Type とか、Macの Mail.app とか。