2

I'm unable to run yum command on my Linux machine.
I'm getting the following errors:

dispsim:~$ yum
Failed to set locale, defaulting to C
Loading "rhnplugin" plugin
Loading "security" plugin
error: cannot open Packages index using db3 - Invalid argument (22)
error: cannot open Packages database in /var/lib/rpm
Traceback (most recent call last):
  File "/usr/bin/yum", line 29, in ?
    yummain.main(sys.argv[1:])
  File "/usr/share/yum-cli/yummain.py", line 85, in main
    base.getOptionsConfig(args)
  File "/usr/share/yum-cli/cli.py", line 163, in getOptionsConfig
    disabled_plugins=self.optparser._splitArg(opts.disableplugins))
  File "/usr/lib/python2.4/site-packages/yum/__init__.py", line 164, in _getConf
ig
    self._conf = config.readMainConfig(startupconf)
  File "/usr/lib/python2.4/site-packages/yum/config.py", line 685, in readMainCo
nfig
    yumvars['releasever'] = _getsysver(startupconf.installroot, startupconf.dist
roverpkg)
  File "/usr/lib/python2.4/site-packages/yum/config.py", line 752, in _getsysver
    idx = ts.dbMatch('provides', distroverpkg)
TypeError: rpmdb open failed

Redhat-release is Red Hat Enterprise Linux Server release 5.2 (Tikanga)

dispsim-1:~$ uname -a
Linux dispsim 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:12 EDT 2008 i686 i686 i386 GNU/Linux

I also tried the following steps:

1. su
2. rm /var/lib/rpm/__db.00*
3. rpm --rebuilddb

But this didn't resolve the issue. Any suggestions on this please?

5
  • Please don't post pictures of text. Just put the text itself into your question.
    – larsks
    Aug 31, 2015 at 12:13
  • @larsks: Ok, made the changes.
    – ani627
    Aug 31, 2015 at 12:40
  • 1
    Did the rpm --rebuilddb command log any errors? When was the last time rpm was working correctly? Have there been any other problems (filesystem corruption, etc) prior to this issue? What version of rpm is installed (rpm --version)?
    – larsks
    Aug 31, 2015 at 12:43
  • @larsks: 1. rpm --rebuilddb command didn't throw any errors. 2. Many months ago I was able to run yum clean all. 3. I haven't seen any issues of filesystem corruption everything else is working fine. 4. The Rpm version is 5.0.
    – ani627
    Aug 31, 2015 at 12:53
  • 2
    RHEL 5.x ships with RPM version 4.4.2.3 (or similar 4.4.x version). It looks like maybe you have installed an incompatible version of rpm? Hard to tell.
    – larsks
    Aug 31, 2015 at 13:42

2 Answers 2

2
+50

Try as su :

tar cvzf rpmdb-backup.tar.gz /var/lib/rpm
rm -f /var/lib/rpm/__db*
rpm --rebuilddb
rpm -qa  | sort

If this fails, execute first lsof | grep /var/lib/rpm and If it finds any, kill -9 them all.

You could also try this sequence :

rm -f /var/lib/rpm/__db*
rpm --initdb
rpm --rebuilddb

If nothing works, copy the rpm database from a backup (or a nearly identical computer).

For the problem with locale, see the article adjust locale settings on CentOS 7, that advises to add to /etc/profile.d/locale.sh commands such as:

export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
3
  • Tried executing these commands, still no luck :(
    – ani627
    Oct 30, 2015 at 18:48
  • I have expanded my answer above.
    – harrymc
    Nov 1, 2015 at 9:25
  • Thanks for the help @harrymc. Nothing worked then I just copied /var/lib/rpm (tar and zip the folder) from another identical machine. After restarting the VM, yum worked. Thanks again :) Awarding bounty and +1 to you from my side :)
    – ani627
    Nov 4, 2015 at 11:34
1

It seems you upgraded from 2010 RPM builds. Previously, SQLite was used to store information about packages, now it's BDB. You probably need to migrate your database.

To do so, you can run the following commands:

rpm --define '_dbapi 4' --rebuilddb
mv /var/lib/rpm /var/lib/rpm.bak
mv /var/lib/rpm.rebuild /var/lib/rpm

You can then test the new database with:

rpm -qa

Then it should work without issues.

5
  • After executing rpm --define '_dbapi 4' --rebuilddb, /var/lib/rpm.rebuild folder is not created.
    – ani627
    Oct 30, 2015 at 4:53
  • Try running updatedb and then locate rpm.rebuild and check if it returns anything.
    – nKn
    Oct 30, 2015 at 6:53
  • rpm.rebuild not found ever after running updatedb :(
    – ani627
    Oct 30, 2015 at 18:46
  • Seems that in newer versions, the rebuilding happens in the /var/lib/rpm directory. Did you try running yum after running the rpm --define '_dbapi 4' --rebuilddb command?
    – nKn
    Oct 30, 2015 at 20:11
  • it still did not work. Thanks for the help. harrymac steps worked for me. +1 form my side for helping me :)
    – ani627
    Nov 4, 2015 at 11:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .