You are updating the system through yum command and suddenly power goes down or what happen if yum process is accidentally killed. Post this situation when you tried to update the system again with yum command now you are getting below error message related to rpmdb:
error: rpmdb: BDB0113 Thread/process 2196/139984719730496 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
You are also not able to perform rpm query and getting same error message on screen:
[root@testvm~]# rpm -qa
error: rpmdb: BDB0113 Thread/process 7924/139979327153984 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: BDB0113 Thread/process 7924/139979327153984 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 database in /var/lib/rpm
[root@testvm ~]# rpm -Va
error: rpmdb: BDB0113 Thread/process 7924/139979327153984 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: BDB0113 Thread/process 7924/139979327153984 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 database in /var/lib/rpm
error: rpmdb: BDB0113 Thread/process 7924/139979327153984 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 database in /var/lib/rpm
[root@testvm~]#
The reason for this error is rpmdb or RPM Database has corrupted. No worry it is easy to recover the rpmdb by following below steps:
1. Create backup directory in which you need to dump the rpmdb backup.
# mkdir /tmp/rpm_db_bak
2. Backup the rpmdb files in created backup directory in /tmp
# mv /var/lib/rpm/__db* /tmp/rpm_db_bak
3. Now rebuild the rpmdb with below commands:
# rpm --rebuilddb -vv
# rpmdb_verify Packages
4. Clean the yum cache from below command:
# yum clean all
5. Now again run the yum update command. It should fetch and apply the updates from your or RHSM (or CentOS CDN in case of CentOS Linux) repositories:
[root@testvm ~]# yum update
Loaded plugins: fastestmirror
base | 3.6 kB 00:00
epel/x86_64/metalink | 5.0 kB 00:00
epel | 4.3 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
(1/7): base/7/x86_64/group_gz | 155 kB 00:02
(2/7): epel/x86_64/group_gz | 170 kB 00:04
(3/7): extras/7/x86_64/primary_db | 191 kB 00:12
(4/7): epel/x86_64/updateinfo | 809 kB 00:21
(5/7): base/7/x86_64/primary_db | 5.6 MB 00:26
(6/7): epel/x86_64/primary_db | 4.8 MB 00:46
(7/7): updates/7/x86_64/primary_db | 7.8 MB 00:50
Determining fastest mirrors
* base: mirror.ehost.vn
* epel: repo.ugm.ac.id
* extras: mirror.ehost.vn
* updates: mirror.dhakacom.com
Resolving Dependencies
--> Running transaction check
---> Package NetworkManager.x86_64 1:1.4.0-19.el7_3 will be updated
---> Package NetworkManager.x86_64 1:1.4.0-20.el7_3 will be an update
---> Package NetworkManager-adsl.x86_64 1:1.4.0-19.el7_3 will be updated
[...]
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
kernel x86_64 3.10.0-514.26.2.el7 updates 37 M
python2-libcomps x86_64 0.1.8-3.el7 epel 46 k
replacing python-libcomps.x86_64 0.1.6-13.el7
Updating:
NetworkManager x86_64 1:1.4.0-20.el7_3 updates 2.5 M
NetworkManager-adsl x86_64 1:1.4.0-20.el7_3 updates 146 k
NetworkManager-bluetooth x86_64 1:1.4.0-20.el7_3 updates 165 k
NetworkManager-glib x86_64 1:1.4.0-20.el7_3 updates 385 k
NetworkManager-libnm x86_64 1:1.4.0-20.el7_3 updates 443 k
NetworkManager-team x86_64 1:1.4.0-20.el7_3 updates 147 k
python-perf x86_64 3.10.0-514.26.2.el7 updates 4.0 M
sudo x86_64 1.8.6p7-23.el7_3 updates 735 k
systemd x86_64 219-30.el7_3.9 updates 5.2 M
systemd-libs x86_64 219-30.el7_3.9 updates 369 k
systemd-sysv x86_64 219-30.el7_3.9 updates 64 k
tuned noarch 2.7.1-3.el7_3.2 updates 210 k
xfsprogs x86_64 4.5.0-10.el7_3 updates 895 k
Removing:
kernel x86_64 3.10.0-123.el7 @anaconda 127 M
Transaction Summary
================================================================================
Install 2 Packages
Upgrade 46 Packages
Remove 1 Package
Total download size: 84 M
Is this ok [y/d/N]: y
rpm –rebuilddb -vv fails:
rpm –rebuilddb -vv
D: rebuilding database /var/lib/rpm into /var/lib/rpmrebuilddb.19417
D: creating directory /var/lib/rpmrebuilddb.19417
D: opening old database with dbapi 3
D: opening db environment /var/lib/rpm cdb:mpool:joinenv
rpmdb: Thread/process 9999/140529926793120 failed: Thread died in Berkeley DB library
error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
D: opening db index /var/lib/rpm/Packages rdonly mode=0x0
error: cannot open Packages index using db3 – (-30974)
D: removing directory /var/lib/rpmrebuilddb.19417
Hi John, It seems this command is trying to rebuild the existing rpm db but as this existing db is corrupted that is why you are getting error. So as I mentioned in my article create one directory in /tmp and move the rpm db to /tmp path example:
mv /var/lib/rpm/__db* /tmp/rpm_db_bak
And then after try to run the rpmbuild db command.