User Tools

Site Tools


Compact Firefox DB on Linux and speed up opening

Mozilla Firefox uses sqlite3 DBs to store it's stuff. These DBs get fragmented because of adding and deleting rows. That's why I made this simple script to cope with the problem.
# v. 1.0.0 
# Compacts all Firefox DBs
# LGPL licence
# Syntax: ./
# Requires sqlite3 v.10
# If you see errors like "encrypted or malformed DB..." it means you have to get
# a newer version of sqlite to be compatible with your Firefox version.
sqlitebin='/opt/lampp/bin/sqlite3-v10'; #path to your sqlite3 binary
tot_word='total'; #important for grep: use that of your language. en="total" it="totale"
read -p "Close any instance of Firefox and press any key."
bef=$(find ~/.mozilla -type f -name \*.sqlite -exec du -ch {} + | grep "$tot_word"$)
find ~/.mozilla -type f -name \*.sqlite -exec $sqlitebin {} "VACUUM" \;
find ~/.mozilla -type f -name \*.sqlite -exec $sqlitebin {} "REINDEX" \;
aft=$(find ~/.mozilla -type f -name \*.sqlite -exec du -ch {} + | grep "$tot_word"$)
echo "Before: "$bef, "After: $aft"
read -p "Press any key to close."

The variable tot_word must contain the exact word the command du uses on your system to show the total. If your system is not english, use this command

du -chs

to check which word your system uses instead of the english “total”.

linux/bash/compact-firefox-db-on-linux-and-speed-up.txt · Last modified: 2016/01/20 12:43 by rik