"Reading Database" takes too long

Bug #398870 reported by polvoazul
194
This bug affects 39 people
Affects Status Importance Assigned to Milestone
apt (Ubuntu)
Fix Released
Undecided
Unassigned
dpkg (Debian)
New
Unknown

Bug Description

Binary package hint: apt

I know that the step Reading Database depends on the number of packages i have installed. But now it is taking so long that it is unbereable. For me to install a small program, it takes more time reading database than anything else.

I have two sugestions to speed up that process, i dont know if they can help, but here they are:

* Cache the database information in some kind of file. Just like the 'updatedb' and 'locate'.

* multithread the aplication to read the database from the start of the process, so that it downloads and reads at the same time. clearly these two things are independent and this would probably save some time.

And please can someone inform me why is it so slow? does it check your hardrive on every single package?
How many packages a clean ubuntu has? mine has 229452 files and directories currently installed. (i have ubuntu-studio-audio)

thank you very much.

Using apt 0.7.20.2ubuntu6 for i386 compiled on Apr 17 2009 04:25:29
Ubuntu 9.04 Jaunty

Tags: apt
polvoazul (fredpublico)
tags: added: apt
Revision history for this message
Atanas Atanasov (thenasko) wrote :

I recently notices a significant slow down in the "reading database" operation after updating to Jaunty. This is most probably a similar issue, though not necessarily identical.

Changed in apt (Ubuntu):
status: New → Confirmed
Revision history for this message
Steven (stebalien) wrote :

This problem is also discused in bug report #69192 on bugs.debian.org (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=69192).

Revision history for this message
polvoazul (fredpublico) wrote :

This bug report http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=69192 is 9 years old, is it still not taken care of?

Revision history for this message
Arnaud Jeansen (ajeans) wrote :

I remembered seeing a blog entry about it some time ago...

http://antti-juhani.kaijanaho.fi/newblog/archives/521

I did the two steps mentioned there and it really made a difference for me:
$ sudo dpkg --clear-avail
$ sudo dpkg --forget-old-unavail

Hope this helps.

Revision history for this message
Eddie Dunn (eddie-dunn) wrote :

Thanks, Arnaud, that really helped me too!

Every time I use apt I get annoyed when I remember how much faster pacman for Arch Linux is. I've used Arch, but don't want to go back there -- can't something be done to speed up apt?

Changed in dpkg (Debian):
status: Unknown → New
Revision history for this message
Sam Freilich (l33tminion) wrote :

Is this just a problem for upgrades? If so, maybe it would be sufficient to just make the commands above part of the upgrade process.

Revision history for this message
Daniel Kończyk (drmartens) wrote :

You mean OS upgrades or package upgrades?
Still, it feels like a regression in Karmic, because I cannot recall anything like this since I've been running Feisty on this machine.

Revision history for this message
Michał Gołębiowski-Owczarek (mgol) wrote :

On my 4-year-old notebook on Hardy "Reading database" used to go fast. Now I have Core2 Duo P8600 (2,4 GHz) and on Karmic it goes slowly with steps 5%-sized, maybe 3 such steps per second. What takes so much time? It was faster in the past...

On the other side, I don't get why apt in Ubuntu still doesn't download deltas only - it's also killing Canonical servers so I think it should be a priority...

Revision history for this message
Michał Gołębiowski-Owczarek (mgol) wrote :

Moreover, I checked and this "reading database" goes fast even on virtual machine run on VirtualBox if only I run older Ubuntu! What has happened to apt?

Revision history for this message
Michał Gołębiowski-Owczarek (mgol) wrote :

This dpkg-related bug isn't actually what we're talking about. Sure, it causes apt to be slower than it could be but it still doesn't explain Karmic regression here.

Revision history for this message
Anakin Starkiller (sunrider) wrote :

I can confirm this issue on Karmic too....

Revision history for this message
Philipp Weissenbacher (philipp-weissenbacher) wrote :

On the Debian mailing-list this has been dicussed here http://<email address hidden>/msg245661.html.

One solution that helped me a bit (just one or two seconds faster) is the following (taken from ):
1. $ sudo su
1. % for x in /var/lib/apt/lists/*Packages;do dpkg --merge-avail "$x";done
2. Rebuild /info (to work against fragmentaton; for me this took +3 minutes!)
  % cd /var/lib/dpkg/
  % cp -a info info.tmp
  % mv info info.orig
  % mv info.tmp info
3. Finally: % dpkg --clear-avail

_and_ reboot (for whatever reason ...)

On the mailinglist above there was also a pointer to http://people.debian.org/~seanius/dpkg-sqlite/ for a proof-of-concept sqlite powered cache, which would fix the slowness problems.

Revision history for this message
Anakin Starkiller (sunrider) wrote :

Philipp Weissenbacher >> unfortunately, this workaround doesn't change anything for me...
Maybe it's because I was using aptitude full-upgrade ? I'll try with apt-get next time ;)

Revision history for this message
Graham Poulter (grahampo) wrote :

#12 (Phillip Weissenbacher's) solution worked for me! -

https://bugs.launchpad.net/ubuntu/+source/apt/+bug/398870/comments/12

I don't know how much good the dpkg --merge-avail "$x" did, but making a copy of "/var/lib/dpkg/info" to defragment it did take a few minutes to complete, and afterwards the "reading database" was MUCH faster!

Revision history for this message
Graham Poulter (grahampo) wrote :

A moment ago, I did another copy of "/var/lib/dpkg/info"

This time it took 1 second to copy, whereas the first time took about 3 minutes.

So for me, I conclude that the cause of reading database taking 5+ seconds was fragmentation of /var/lib/dpkg/info

Revision history for this message
Hans van den Bogert (hbogert) wrote :

we should get a button to mark a comment as a viable solution.

Just like graham, the first copy took ages, but the reading now takes place within 2 seconds, where it used to be 30s.
Thanks! Philipp Weissenbacher, this is some HUGE performance gain, I always suspected fragmentation was an issue on my small 40GB partition.

Revision history for this message
Eddie Dunn (eddie-dunn) wrote :

It is a workaround, not a solution.

A solution would be if this were solved automatically so users wouldn't have to track down this bug report in order to have sane package database reading times.

Revision history for this message
Graham Poulter (grahampo) wrote :

Cron work-around: a weekly "cd /var/lib/dpkg && mv info info.bak && cp -a info.bak info && rm -R info.bak" to keep the directory contiguous.

ReiserFS work-around: create a ReiserFS partition especially to hold /var/lib/dpkg/info. ReiserFS was specifically designed to handle zillions of tiny files in one massive directory (under the philosophy that databases mostly because filesystems aren't up to the task). As /var/lib/dpkg/info demonstrates, ext3 is having having fragmentation trouble on huge database-like directories.

Short-term solution: Have the default Ubuntu installation defragment /var/lib/dpkg/info regularly

Long-term solution: Have dpkg use a database instead of /var/lib/dpkg/info. I deduce that the person who specified /var/lib/dpkg/info as a massive directory of tiny files was expecting ReiserFS to become the standard filesystem. Since that's not going to happen, it's about time to use a database.

Revision history for this message
Graham Poulter (grahampo) wrote :

Sorry, the "long-term solution" does not explain why "Reading database" used to be fast under older versions of Ubuntu. Can anyone explain why fragmentation came to be a problem for /var/lib/dpkg/info in recent versions of Ubuntu?

Revision history for this message
Michał Gołębiowski-Owczarek (mgol) wrote :

I don't know what exactly this "workaround" does, but it does NOT work for me at all. "Reading database" in Karmic still lasts ages as opposed to what used to be in Hardy.

Revision history for this message
frt975 (frt975-deactivatedaccount) wrote :
Revision history for this message
Akshay (akshaykkulkarni) wrote :

For me, this solved the problem:

apt-get clean

This basically deletes all the downloaded ".deb" files (which are no longer needed after they have been installed), which has the added advantage of freeing up some disk space.

Revision history for this message
Akshay (akshaykkulkarni) wrote :

edit to my comment above - apt-get clean doesn't actually solve this problem. I was seeing a speed-up simply due to the database being in the hard drive cache :(

Revision history for this message
Philipp Weissenbacher (philipp-weissenbacher) wrote :

In fact a database has already been implemented. See the following Brainstorm Idea: http://brainstorm.ubuntu.com/idea/24027/

If you want that feature, please vote for this idea!

Revision history for this message
Luca Bruno (lucabru) wrote :

I'd like to remember you all dpkg/experimental is a lot faster now... from about 14sec to 3sec here. Well using the database would be about 1sec but I wouldn't recommend to a distribution to use a wrapper (just like I don't recommend installing the library in your system, not because it's unstable but because a bad user usage could lead to unexpected results for the system). Patch dpkg directly instead.

Revision history for this message
Anakin Starkiller (sunrider) wrote :

This bug has been fixed in Lucid.

Kwinz (ldm)
Changed in apt (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
Mike.lifeguard (mikelifeguard) wrote :

Could we get a pointer to the commit which fixed this in apt? I assume this will go in lucid-proposed and such, yes?

Revision history for this message
torzsmokus (torzsmokus) wrote :

will there be a Jaunty backport?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.