Speedup Package Management
Appearance
Speeding up the package manager
Package Management is one part of the system where massive databases are thrown around, changed incrementally and is generally used heavily. Due to incremental nature of modifications it will cause the databases used to fragment, both internally (in the database blob) and externally (on the disk).
In openSUSE 10.3 we have two kinds of databases for package management.
- The zypp cache SQLITE database in
/var/cache/zypp/zypp.db. - The RPM database in
/var/lib/rpm/.
Defragment internally
- Cleaning up sqlite databases can be done using the
VACUUMcommand.
- For the ZYPP cache database:
sqlite3 /var/cache/zypp/zypp.db vacuum- Or alternatively regenerate it from scratch:
rm /var/cache/zypp/zypp.db ; zypper refresh
- Defragmenting the RPM database
- After largish update it is helpful to run
rpm --rebuilddbonce.
- This is just necessary after lots of packages changed/updated/installed and takes some time (10 minutes on a Laptop).
Defragment externally
While Linux filesystems try to not create heavily fragmented files, the slow increasing nature of the databases used in packagemanagement has fragmentation patterns.
So to best way to get rid of it, is to recreate the files using the pattern:
cp file file.new # check for errors! rm file mv file.new file
- zypp database
- Either remove it and regenerate it using
zypper refreshor just apply - the cp/rm/mv on
/var/cache/zypp/zypp.db.
- RPM database
- Use the cp/rm/mv trick on
/var/lib/rpm/Packages, Basenames, Filemd5s, Dirnames
Sample script
#!/bin/sh
sqlite3 /var/cache/zypp/zypp.db vacuum
rpm --rebuilddb # takes long
for fn in /var/cache/zypp/zypp.db \
/var/lib/rpm/Packages \
/var/lib/rpm/Filemd5s \
/var/lib/rpm/Dirnames \
/var/lib/rpm/Basenames
do
cp $fn $fn.new || exit 1
rm $fn
mv $fn.new $fn
done
<keyword>zypp,rpm,speed,package management</keyword>