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
- I recommend all of you visiting Daniel Berrange excellent guide for more information.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 10 comments… read them below or add one }
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.
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.
How to recreate /var/lib/rpm/Packages (If original got deleted/corrupted) ?
Thank You! you saved my day.
Thank You! you saved my day
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”.
Thank You! you saved my day.
first command is cd /var/lib/rpm and not /var/lib
cd /var/lib/rpm
not #cd /var/lib/
nixcraft to the rescue!