Recover the RPM database on Fedora 18

Author: | Posted in howto 11 Comments

RPMRPM is a package management tool, a core component of many Linux distributions such as Red Hat, Fedora, CentOS and many others. It stores information about software packages in its own database which is available under /var/lib/rpm. Sometimes the database can become corrupted so any attempt to make use of the rpm system would fail. The failure affects both the rpm command and the yum tool so any standard package operation such as installing / querying / verifying would throw an error.

This recently happened on my Fedora 18, I was trying to do a manual update and I got this error:

sudo yum update
error: rpmdb: BDB0113 Thread/process 2174/139838549436224 failed: BDB1507 Thread died in Berkeley DB library
error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db5 -  (-30973)
error: cannot open Packages database in /var/lib/rpm

Error: rpmdb open failed


Luckily I knew what I had to do (with some help of a couple of older guides I found on the Internet).


step1: verify there’s no lock on the rpm database that is causing the error

sudo db_stat -CA

Check under “Locks grouped by lockers” and “Locks grouped by object”. Those should display nothing. If there are any rpm processes, investigate them further:

sudo ps ax | egrep  '[r]pm|[y]um'
sudo lsof | grep /var/lib/rpm

If you get any rpm / yum output try to kill the processes manually. If that doesn’t help and the rpm database still returns errors then it’s time to recover it.


step2: make a backup of the current rpm database

cd /var/lib
sudo tar czvf /var/preserve/rpmdb-`date +"%d.%m.%Y"`.tar.gz rpm

ll /var/preserve/
total 48092
-rw-r--r-- 1 root root 49245072 Mar  2 19:40 rpmdb-02.03.2013.tar.gz


step3: verify the Packages file, recover if needed

cd /var/lib/rpm
sudo rm -f __db*
sudo db_verify Packages

In case the verify command returns any errors you need to recover the file:

sudo mv Packages Packages.bkp
sudo db_dump Packages.bkp | sudo db_load Packages

This dumps the current packages info to the db_load utility which creates a new Packages file.


step4: rebuild the rpm database

sudo rpm -v --rebuilddb


step5: verify the database is working and you can successfully query all files

rpm -qa 1 > /dev/null

You can also perform a sanity check to ensure there are no more errors.

sudo db_log_verify

Hope this helps.

  1. Posted by Elex
  2. Posted by Mark
  3. Posted by dizel
  4. Posted by Админ всея руси
  5. Posted by Wei Shen
  6. Posted by John
  7. Posted by Martijn van Dijk
  8. Posted by ratna
  9. Posted by Luca Innocenti
  10. Posted by Akira

Add Your Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.