If your dpkg runs seem to take a long time in the “reading database” step, try this:
Step One: Clear the available file dpkg --clear-avail
Step Two: Forget old unavailable packages dpkg --forget-old-unavail
Step Three: If you use grep-available or other tools that rely on a useful available file, update the available file using sync-available (in the dctrl-tools package).
The few times I’ve tried it (all situations where the “reading database” step seemed to take ages), it has always sped the process up dramatically. There probably are situations where it won’t make much difference, but I haven’t run into them.








2.5.2009 klo 14:54
Actually, reading the available file should not take that long. The
bottleneck is elsewhere, in reading the (typically) 1000+
/var/lib/dpkg/info/*.list files that are scattered all over the
filesystem. This is what makes dpkg so slow, but it is usually
confined to the first package installation or search — after that,
the files are in the operating system’s cache, unless your system is
tight on RAM.
Running sync-available will recreate and thus defragment the
available file, but that does not usually have a great effect.
2.5.2009 klo 15:39
What you said probably is true. Nevertheless, I have observed great gains in speed from this, and the cache effect doesn’t explain them (since I usually get fed up with the problem after *repeated* uses of dpkg -i).
5.5.2009 klo 16:31
thanks for the tip – it did speed up start up of aptitude a great deal
6.5.2009 klo 9:24
Thanks! this has long been a bane of my existance… having to wait almost a minute sometimes.
*adds these commands to cron*
31.10.2009 klo 23:23
Thanks, this made a huge difference for me.
2.11.2009 klo 4:32
As of Ubuntu 9.10,
dpkg: warning: obsolete ‘–forget-old-unavail’ option, unavailable packages are automatically cleaned up.
10.6.2010 klo 8:38
[...] to fix your slow dpkg and apt-get requests. Here is a link to the website where I found the guide: http://antti-juhani.kaijanaho.fi/newblog/archives/521 I will list the commands that I had to execute to fix the issue. dpkg –clear-avail sync-available [...]