Products and Services Solutions Support and Docs Training About Red Hat Re: Corrupt rpm database

Re: Corrupt rpm database

Hash: SHA1

On Wednesday 01 January 2003 06:57 pm, Cliff Wells wrote:
> I seem to have lost my rpm database.  After upgrading a couple of rpms,
> rpm would fail, telling me to run recover (whatever the hell that is -
> couldn't find any reference to such a thing in the rpm man page).
> Anyway, tried rpm --rebuilddb which also failed the first time, but
> seemed to work the second time I ran it.  However, I then checked with
> rpm -qa and there was only a single package listed.  I looked in
> /var/lib and found a directory called rpmrebuilddb.1908.  I moved
> /var/lib/rpm to a safe place and copied the rpmrebuilddb.1908 directory
> to /var/lib/rpm.  Ran rpm --rebuilddb again.  Now I have a rpm database
> with plenty 'o stuff in it, but I'm sure it's out of date.  No problem,
> I think, I'll just run apt-get upgrade and bring it back into sync
> (probably with some missing packages that I'll worry about later).
> Unfortunately apt-get reports a bunch of unmet dependencies and refuses
> to fix them (even using -f).

Well, it depends on how daring you want to get.... ;)

The version of RPM included with the 8.0 release is prone to getting hung, 
and leaving the database in need of repair.

Generally, it is easily repaired with:
rm -f /var/lib/rpm/__db*
rpm --rebuilddb

What you can try is:
Download and install the test release of rpm, which has been working here 
for about a month without problems.

If you look in /var/log/rpmpkgs, you should have a complete list of all 
the packages instaled on your system as of 4:00 AM today. If you have the 
install CD's, you have access to most of the packages you have installed. 
If you've kept the updated packages around as well, you're in excellent 

Then, grab my quick hack of a script to rebuild the database. It's not 
pretty, but should help. For each package listed in the given file 
(/var/log/rpmpkgs) it will search the given paths for matching rpms, and 
run 'rpm -ivh --justdb --force --nodeps $package'.

Move your existing rpm database out of the way.
# mv /var/lib/rpm /var/lib/

Initialize a new rpm database:
# rpm --initdb

Run the script.
# ./ -f /var/log/rpmpkgs -p /mnt/cdrom/Redhat/RPMS 

(assuming a valid filelist in /var/log/rpmpkgs, a mounted Red Hat CD in 
/mnt/cdrom, and updates in /var/spool/up2date.)

You'll have to run it once for each CD, and it'll spew warnings about 
packages not found for every package not on the current CD.

If it works: 
Thanks for testing, and congratulations!

If it doesn't work:
Sorry, thanks for testing. Please restore your previous rpm database. ;)

On the upside, I have tested it, and it does work. It will take some time 
to complete though. Obviously, if there are packages on your system that 
you don't have available, they won't be included in the restored 

Good luck. Hope it helps,
- -- 
- -Michael

pgp key:
Red Hat Linux 7.{2,3}|8.0 in 8M of RAM:
- --
Version: GnuPG v1.0.7 (GNU/Linux)


Copyright © 2003 Red Hat, Inc. All rights reserved. Search by Google
Careers at Red Hat : Legal statement : Privacy statement : Your Account : Contact Red Hat


   Powered By Red Hat Linux