How to recover from corrupt rpm database on RHEL/CentOS/Fedora

In this article I am going to show you a trick to recover from a corrupt rpm database…which might make the system defunct.As a direct result of that you just cannot install/upgrade/update the software in rpm base system like RHEL,CentOS and Fedora.

First and foremost thing take a backup of the existing rpm database( yes the corrupted one…you never know…).This is located in /var/lib/rpm ..depend on your distribution.

Now go to that dir(/var/lib) and take a backup of entire rpm dir ..like this:

tar -cvzf rpm-date.tar.gz rpm

And finally start rebuilding the rpm database like this:

cd /var/lib/rpm

rm -f __db* # delete it if present

rpm –rebuilddb -vv

Now once the above command finished work..other related thing should start working i.e

yum update

yum install anypackage

rpm -qi packagename

Don’t forget to check the system log file in case it spitting put other msg.

Hope this will help.

Bhaskar Chowdhury

About unixbhaskar
GNU/Linux Consultant

4 Responses to How to recover from corrupt rpm database on RHEL/CentOS/Fedora

  1. Rajnish Kumar says:

    Hi i am facing the same problem , i an not able to install any rpm through rpm commands or yum .
    when i run rpm -ivh package name i got below error :
    error: can’t create transaction lock on /var/lib/rpm/__db.000
    even i am not able to remove the /var/lib/rpm then __db.00* file
    i got the below error :=
    [root@Rajnish rpm]# rm -rf __db.00*
    rm: cannot remove `__db.001′: Permission denied
    rm: cannot remove `__db.002′: Permission denied
    rm: cannot remove `__db.003′: Permission denied
    [root@Rajnish rpm]#

    i am using centos 5.4 for Detaill :-
    uname -a
    Linux Rajnish 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:14 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

    any suggestion . how can i get out from here .

    • unixbhaskar says:

      Now you have few options to check:

      1) run a command as root : getenforce

      and show me the result.

      2) run the command getfacl on /var/lib/rpm and show me the result.

      3) why rm -rf ??? it should be rm -f ..R stand for recursive..and you don’t need it.

      4) get me the result of ps -ef | grep yum

      5) What your log says: tail -f /var/log/messeges or /var/log/secure

      • rajnish says:

        Hi ,
        thanks for your Reply .
        below is the data asked by you .
        getenforce
        Disabled
        [root@Rajnish rpm]# getfacl /var/lib/rpm
        getfacl: Removing leading ‘/’ from absolute path names
        # file: var/lib/rpm
        # owner: root
        # group: root
        user::rwx
        group::r-x
        other::r-x

        [root@Rajnish rpm]# ps -ef | grep yum
        root 3078 1 0 12:27 ? 00:00:00 /usr/bin/python -tt /usr/sbin/yum-updatesd
        root 13765 12506 0 15:30 pts/4 00:00:00 grep yum
        [root@Rajnish rpm]#

        and log files doesn’t contain anything regarding this issues .

      • rajnish says:

        Hi ,
        thanks for your Reply .
        below is the data asked by you .
        getenforce
        Disabled
        [root@Rajnish rpm]# getfacl /var/lib/rpm
        getfacl: Removing leading ‘/’ from absolute path names
        # file: var/lib/rpm
        # owner: root
        # group: root
        user::rwx
        group::r-x
        other::r-x

        [root@Rajnish rpm]# ps -ef | grep yum
        root 3078 1 0 12:27 ? 00:00:00 /usr/bin/python -tt /usr/sbin/yum-updatesd
        root 13765 12506 0 15:30 pts/4 00:00:00 grep yum
        [root@Rajnish rpm]#

        and log files doesn’t contain anything regarding this issues .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: