Linux 操作系统的发行版本如 :redhat、CentOS、SUSE 中,采用 RPM 来管理软件包,不过在使用过程中,因为各种原因导致 rpmdb 被损坏需要进行恢复。
rpmdb: /var/lib/rpm/Packages: unexpected file type or format error: cannot open Packages index using db3 - Invalid argument (22) rpmdb: Thread/process 63857/857139875088574 failed: Thread died in Berkeley DB library error: db3 error(-60726) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery error: cannot open Packages index using db3 - (-60726) error: cannot open Packages database in /var/lib/rpm rpmdb: Thread/process63857/857139875088574 failed: Thread died in Berkeley DB library error: db3 error(-60726) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery error: cannot open Packages database in /var/lib/rpm
原因为:rpm会使用自己的 DB 保存元数据,经常在宕机、kill -9 时会损坏 DB ,那么就可能会导致已经安装的包丢失、更新 RPM 被 hang 住、查询包信息失败。
修复rpmdb,流程如下:
进入rpm数据库目录 $sudo cd /var/lib 确保没有rpm进程运行 $ sudo ps -ef | grep -i rpm 备份现有数据库 $sudo mkdir rpm-backup $sudo rsync -av /var/lib/rpm /var/lib/rpm-backup $sudo rm -f /var/lib/rpm/__db* 重构rpm库 $ sudo rpm -vv --rebuilddb >> /tmp/rpm.log 2>&1 重新校验 $ sudo /usr/lib/rpm/rpmdb_verify /var/lib/rpm/Packages BDB5105 Verification of /var/lib/rpm/Packages succeeded.