Rebuilding corrupted RPM database

by on June 3, 2006 · 11 comments· LAST UPDATED October 12, 2006

in , ,

One of our client reported that he is getting an error and RPM database is corrupted. He is using Red Hat Linux

Sometime it is possible to fix RPM database errors. I am surprised that many admins do not make back up of RPM DB (/var/lib/rpm).

Anyways if you ever messed up with RPM database, here is a quick guide to fix it (you must have rpmdb tools installed):

Take system to single user mode to avoid further damage and to make backup/restore process easy:

# init 1

Method # 1

Remove /var/lib/rpm/__db* files to avoid stale locks:
# cd /var/lib
# rm __db*

Rebuild RPM database:
# rpm --rebuilddb
# rpmdb_verify Packages

Method # 2

If you are still getting errors, then try your luck with following commands:

# mv Packages Packages-BAKUP
# db_dump Packages-BAKUP | db_load Packages
# rpm -qa
# rpm --rebuilddb

Further reading

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 11 comments… read them below or add one }

1 Paul Blonde December 5, 2006 at 11:25 pm

Method 2 does not work, as the db_load and db_dump commands were not found. Needless to say if what came before worked I wouldn’t have gotten to 2.

Reply

2 nixCraft December 5, 2006 at 11:35 pm

whereis db_dump db_load
db_dump: /usr/bin/db_dump
db_load: /usr/bin/db_load

These utilities get installed by default using db4-utils package. Above instructions are tested on Fedora Core and RHEL 4 only.

Reply

3 Tapas Mallick August 18, 2008 at 1:18 pm

How to recreate /var/lib/rpm/Packages (If original got deleted/corrupted) ?

Reply

4 James Cassell October 10, 2008 at 5:46 pm

Thank You! you saved my day.

Reply

5 James Cassell October 10, 2008 at 5:46 pm

Thank You! you saved my day

Reply

6 Tapas Mallick October 13, 2008 at 7:55 am

I found the same post/solution before in nixcraft and it is really a great solution but my question is how to recreate /var/lib/Packages if the original got “DELETED”.

Reply

7 com4host.com September 18, 2009 at 5:43 pm

Thank You! you saved my day.

Reply

8 michael November 8, 2009 at 3:09 pm

first command is cd /var/lib/rpm and not /var/lib

Reply

9 Anonymous May 17, 2010 at 6:14 pm

cd /var/lib/rpm

not #cd /var/lib/

Reply

10 mhelix October 18, 2012 at 2:59 pm

nixcraft to the rescue!

Reply

11 Lyubo March 7, 2014 at 6:48 am

For me it worked this one :
rpm -e –justdb

Reply

Leave a Comment

Previous post:

Next post: