# Speedup Package Management

# 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 `VACUUM` command.

<dl id="bkmrk-for-the-zypp-cache-d"><dt></dt><dd>For the ZYPP cache database: </dd><dd>`sqlite3 /var/cache/zypp/zypp.db vacuum`</dd><dd>Or alternatively regenerate it from scratch: </dd><dd>`rm /var/cache/zypp/zypp.db ; zypper refresh`</dd></dl>- Defragmenting the RPM database

<dl id="bkmrk-after-largish-update"><dt></dt><dd>After largish update it is helpful to run `rpm --rebuilddb`once. </dd></dl><dl id="bkmrk-this-is-just-necessa"><dt></dt><dd>This is just necessary after lots of packages changed/updated/installed and takes some time (10 minutes on a Laptop). </dd></dl>## 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

<dl id="bkmrk-either-remove-it-and"><dt></dt><dd>Either remove it and regenerate it using `zypper refresh` or just apply </dd><dd>the cp/rm/mv on `/var/cache/zypp/zypp.db`. </dd></dl>- RPM database

<dl id="bkmrk-use-the-cp%2Frm%2Fmv-tri"><dt></dt><dd>Use the cp/rm/mv trick on `/var/lib/rpm/Packages, Basenames, Filemd5s, Dirnames`</dd></dl>## 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>

[C](Category:SDB:10.3 "wikilink") [C](Category:SDB:Installation "wikilink") [C](Category:SDB:YOU "wikilink")