About nixCraft

Topics

Rebuilding corrupted RPM database

Posted by Vivek Gite [Last updated: October 12, 2006]

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

E-mail this to a Friend    Printable Version

You may also be interested in other helpful articles:

Discussion on This Article:

  1. RPM database location for backup purpose | Frequently Asked Questions Says:

    [...] If you get rpm database corruption error, try to follow instructions mentioned here to fix database problem with following two commands: # rpm –rebuilddb # rpmdb_verify Packages [...]

  2. Paul Blonde Says:

    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.

  3. nixcraft Says:

    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.

  4. Tapas Mallick Says:

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

  5. James Cassell Says:

    Thank You! you saved my day.

  6. James Cassell Says:

    Thank You! you saved my day

  7. Tapas Mallick Says:

    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”.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Powered by Open source software.