解决CentOS在执行yum命令时报错"Error: rpmdb open failed"

2020/07/13 21:15 下午 posted in  技术 comments

今天在日常进行CentOS操作的时候,不知为何yum -y install xxx命令突然卡死不动,Ctrl+C取消执行也无解,遂关闭SSH重新建立连接,然而再次重新执行yum -y install xxx命令时却报如下错误:

...
root@localhost:~>yum -y install xxx
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 27970.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  43 M RSS (362 MB VSZ)
    Started: Mon Jul 13 18:27:38 2020 - 03:46 ago
    State  : Uninterruptible, pid: 27970
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  43 M RSS (362 MB VSZ)
    Started: Mon Jul 13 18:27:38 2020 - 03:48 ago
    State  : Uninterruptible, pid: 27970
...

初步判断应该是进程号为27970的那个假死了,即使刚才SSH关闭了也并没有杀掉他,遂干脆利落的执行了kill -9 27970直接杀死,后再执行yum -y install xxx命令,结果又有报错:

...
root@localhost:~>yum -y install xxx
error: rpmdb: BDB0113 Thread/process 27970/140274709284672 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
...

哦豁,凉了,rpmdb本地数据存储文件炸了……不过好在有解决方法。

执行如下命令,清理YUM仓库本地数据存储文件:

mv /var/lib/rpm/__db* /tmp;

执行如下命令,清理yum缓存:

rpm --rebuilddb;
yum clean all

大功告成。

现在细想一下,yum当时有可能是因为网络问题假死,可能再等等就好了,不过毕竟当时有点着急,以后得注意下。