Linux System Admins Blog

System admins of Promet – an e-commerce, high availability Open Source web shop – share their findings

Linux System Admins Blog header image 2

HowTo recover from a corrupt rpm database

February 10th, 2009 · 8 Comments

RedHat based systems (rhel/fedora/centos) use rpm/yum to install and upgrade packages. If the rpm database gets corrupted in some way it will break all the functionality of rpm and other tools that rely on it like yum for example. We have seen this either showing some errors on the console, or most frequently just by hanging and not performing any rpm related operations (even simple view operations like rpm -qa, or yum update, etc.). You will have to kill the processes and then find a way to rebuild your rpm database. This post will show how to rebuild your rpm database and bring back to life your rpm command.

First we need to backup our existing database (just in case); this is located in /var/lib/rpm and depending on your distribution the content of the folder might look like this:
/var/lib/rpm
-rw-r--r--  1 rpm  rpm   5464064 Feb  9 04:17 Basenames
-rw-r--r--  1 rpm  rpm     12288 Feb  3 05:03 Conflictname
-rw-r--r--  1 root root        0 Aug 25 02:48 __db.000
-rw-r--r--  1 root root    24576 Aug 14 04:02 __db.001
-rw-r--r--  1 root root  1318912 Aug 14 04:02 __db.002
-rw-r--r--  1 root root   450560 Aug 14 04:02 __db.003
-rw-r--r--  1 rpm  rpm   1982464 Feb  9 04:17 Dirnames
-rw-r--r--  1 rpm  rpm   5259264 Feb  9 04:17 Filemd5s
-rw-r--r--  1 rpm  rpm     24576 Feb  9 04:17 Group
-rw-r--r--  1 rpm  rpm     28672 Feb  9 04:17 Installtid
-rw-r--r--  1 rpm  rpm     45056 Feb  9 04:17 Name
-rw-r--r--  1 rpm  rpm  31707136 Feb  9 04:17 Packages
-rw-r--r--  1 rpm  rpm    339968 Feb  9 04:17 Providename
-rw-r--r--  1 rpm  rpm    106496 Feb  9 04:17 Provideversion
-rw-r--r--  1 rpm  rpm     12288 Dec  2 08:45 Pubkeys
-rw-r--r--  1 rpm  rpm    253952 Feb  9 04:17 Requirename
-rw-r--r--  1 rpm  rpm    167936 Feb  9 04:17 Requireversion
-rw-r--r--  1 rpm  rpm     86016 Feb  9 04:17 Sha1header
-rw-r--r--  1 rpm  rpm     49152 Feb  9 04:17 Sigmd5
-rw-r--r--  1 rpm  rpm     12288 Jan 15 21:09 Triggername

Let’s just backup all the /var/lib/rpm folder to have its original state:
cd /var/lib
tar czvf rpmdb.tar.gz rpm

Finally let’s rebuild the rpm database:
cd /var/lib/rpm
rm -f __db*
rpm --rebuilddb -vv

After this, your rpm commands should be working again. (just try a yum update or a rpm query like: rpm -qa php). If this will not fix it try to see what error messages you got from the above commands or from your system logs.

Related Posts:

Tags: Centos · sysadmin

8 responses so far ↓

  • 1 thefox // Mar 12, 2009 at 6:24 am

    Great! It works!

    I thought that was a problem of gpg signatures etc. but nothing worked…
    Finally I found this post and now it’s all right!

    thanks

  • 2 rohan // May 28, 2009 at 1:59 pm

    Whenevr i run this,
    rpm –rebuilddb

    It flashes this message:
    rpm: –hash (-h) may only be specified during package installation

    I installed fedora 10 from live cd.
    And then succefully updated that, using yum.

    But after that during installation of Vuze, my rpm got corrupted amd since then i hafacing many problems please help how to rebuild it.

    It wud be better if you’ll suggest something online itself.

    Thanks

    Regards
    Rohan

  • 3 marius // May 28, 2009 at 2:42 pm

    @Rohan: if you have selinux enabled you might want to try to disable that, and try again. If still doesn’t work run a strace and see where it hits the wall.

  • 4 paul // Dec 5, 2009 at 8:37 pm

    Thank you so much! I was struggling with this for hours and finally your suggestion about deleting __db* was what I was missing! THANK YOU!

  • 5 Phil // Dec 18, 2009 at 5:39 pm

    Hi

    I am new to running a dedicated server. The root panel tells me RPM is corrupt.

    my question is before I da anything is. What does RPM actually do, is it to do with the server speed of the system and uploading servers.

    I ask this because I found this looking at why this server was so slow.

    Cheers

  • 6 HowTo recover from a corrupt rpm database « Chicago Mac/PC Support // May 4, 2010 at 1:01 pm

    [...] from a corrupt rpm database I haven’t faced this issue but its good to be prepared.  A good step by step on how to do [...]

  • 7 Lamont Granquist // May 29, 2010 at 12:43 pm

    might want to try running:

    rpmdb –rebuilddb

    note that the command is “rpmdb” rather than “rpm”

  • 8 javad // Jul 7, 2010 at 6:36 pm

    Thank you so much.

    I was installing some packages that system encountered restart due to power fail; and then I see that I can’t install any software. It was Berkeley DB error and your tutorial helped me build corrupted db again.

Leave a Comment