While rolling out updates on some servers, and without apparent reason, as yum hadn’t failed or thrown any errors before, it failed with DB_RUNRECOVERY: Fatal error, run database recovery:

yum update
Code language: Bash (bash)
Output
error: rpmdb: BDB0113 Thread/process 26477/140596402444352 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 CRITICAL:yum.main: Error: rpmdb open failed
Code language: Bash (bash)

YUM is failing and not accepting any command. While the reason for my YUM database corruption isn’t known, the solution is quite simple and easy to fix with a few steps.

The following commands are performed as root or using sudo:

First lets make a directory to backup the original files

mkdir /tmp/yum_db mv -v /var/lib/rpm/__db* /tmp/yum_db/
Code language: Bash (bash)
Output
‘/var/lib/rpm/__db.001’ -> ‘/tmp/yum_db/__db.001’ ‘/var/lib/rpm/__db.002’ -> ‘/tmp/yum_db/__db.002’ ‘/var/lib/rpm/__db.003’ -> ‘/tmp/yum_db/__db.003’
Code language: Bash (bash)

Now rebuild the yum db:

rpm --rebuilddb
Code language: Bash (bash)

And lets cleanup in the end!

yum clean all
Code language: Bash (bash)
Output
Loaded plugins: fastestmirror Cleaning repos: base epel extras updates Cleaning up list of fastest mirrors
Code language: Bash (bash)

And that’s it. After it finished I just had to run yum update again. Went through smoothly and finished without any issue.

yum update
Code language: Bash (bash)
Output
Loaded plugins: fastestmirror Determining fastest mirrors epel/x86_64/metalink | 29 kB 00:00:00 * base: fs-n.issc.io * epel: mirror.hosting90.cz * extras: centos.schlundtech.de * updates: fs-n.issc.io base | 3.6 kB 00:00:00 epel | 5.3 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/7): base/7/x86_64/group_gz | 165 kB 00:00:00 (2/7): base/7/x86_64/primary_db | 6.0 MB 00:00:00 (3/7): epel/x86_64/group_gz | 90 kB 00:00:00 (4/7): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (5/7): extras/7/x86_64/primary_db | 153 kB 00:00:00 (6/7): updates/7/x86_64/primary_db | 5.8 MB 00:00:00 (7/7): epel/x86_64/primary_db | 6.9 MB 00:00:00 ...
Code language: Bash (bash)

And don’t forget to clean up the files left at /tmp/yum_db.

Should you have any questions left regarding this article, or if you want to discuss it with other users, feel free to leave a comment. 

Leave a Reply

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

Related Posts