CentOS – RPM DB broken

在使用 rpm 指令時遇到下列問題:

error: rpmdb: BDB0113 Thread/process 22583/139896869001280 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 22583/139896869001280 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

建議先備份 rpm DB

# mkdir /var/lib/rpm/backup
# cp -a /var/lib/rpm/__db* /var/lib/rpm/backup/

然後刪除 rpm DB

# rm -rf /var/lib/rpm/__db*

用下列方式重新建立 rpm DB

# rpm --quiet -qa
# rpm --rebuilddb

用 rpm 指令測試有無問題

# rpm -qa

如果沒有問題就可以移除先前的備份

# rm -rf /var/lib/rpm/backup