【EC2】rpmdbが壊れて yum install が失敗する場合の対応方法

yumはrpmを利用してインストールパッケージの依存関係を管理しています。

yum コマンドを実行した際に下記のようなエラーが発生し失敗する場合があります。

$sudo yum install epel-release
$sudo yum install epel-release
Loaded plugins: fastestmirror, priorities, update-motd
amzn-main                                                                                                                                                                                                              | 2.1 kB  00:00:00
amzn-updates                                                                                                                                                                                                           | 3.8 kB  00:00:00
Loading mirror speeds from cached hostfile
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * epel-debuginfo: d2lzkl7pfhq30w.cloudfront.net
 * epel-source: d2lzkl7pfhq30w.cloudfront.net
1067 packages excluded due to repository priority protections
error: rpmdb: Thread/process 28618/140489055352640 failed: Thread died in Berkeley DB library
error: db4 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db4 -  (-30974)
error: cannot open Packages database in /var/lib/rpm
Traceback (most recent call last):
  File "/usr/bin/yum", line 29, in <module>
    yummain.user_main(sys.argv[1:], exit_code=True)
  File "/usr/share/yum-cli/yummain.py", line 365, in user_main
    errcode = main(args)
  File "/usr/share/yum-cli/yummain.py", line 174, in main
    result, resultmsgs = base.doCommands()
  File "/usr/share/yum-cli/cli.py", line 574, in doCommands
    return self.yum_cli_commands[self.basecmd].doCommand(self, self.basecmd, self.extcmds)
  File "/usr/share/yum-cli/yumcommands.py", line 437, in doCommand
    return base.installPkgs(extcmds, basecmd=basecmd)
  File "/usr/share/yum-cli/cli.py", line 974, in installPkgs
    txmbrs = self.install(pattern=arg)
  File "/usr/lib/python2.7/dist-packages/yum/__init__.py", line 4920, in install
    ipkgs = self.rpmdb.searchNames([po.name])
  File "/usr/lib/python2.7/dist-packages/yum/rpmsack.py", line 1285, in searchNames
    returnList.extend(self._search(name=name))
  File "/usr/lib/python2.7/dist-packages/yum/rpmsack.py", line 1350, in _search
    for hdr, idx in mi:
  File "/usr/lib/python2.7/dist-packages/yum/rpmsack.py", line 1304, in _get_packages
    mi = ts.dbMatch(*args, **kwds)
  File "/usr/lib/python2.7/dist-packages/rpmUtils/transaction.py", line 58, in dbMatch
    mi = self.ts.dbMatch(*args, **kwds)
_rpm.error: rpmdb open failed

rpmdbの修正方法

rpmコマンドのリビルドオプションでrpmdbを修復します。

$sudo  rpm --rebuilddb

戻り値がなければ成功です。

$ yum install epel-release

Loaded plugins: fastestmirror, priorities, update-motd
Loading mirror speeds from cached hostfile
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * epel-debuginfo: d2lzkl7pfhq30w.cloudfront.net
 * epel-source: d2lzkl7pfhq30w.cloudfront.net
1067 packages excluded due to repository priority protections
Package epel-release-6-8.9.amzn1.noarch already installed and latest version
Nothing to do

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA