Friday, January 18, 2008

HowTo: Rebuild Locked Out RPM Database

Every time you query rpm database against your rpm package manager, your linux terminal and query seems to hang and you cannot do something about it except try to kill and terminate the current rpm query process.

One probable cause for this could be a recent rpm query was unexpectedly terminated by hitting Control+C, that left rpm on a inaccurate state or rpm stale lock status. RPM when terminated unexpectedly cannot flush out pending query jobs from it thus, leaving rpm database with an inaccurate rpm database lock state.

Repair RPM Database Files

Take a look at rpm database usually found here from Fedora box
# cd /var/lib/rpm
# ls -la

You will see similar lines like these
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-rw-r--r-- 1 root root 24576 2008-01-18 17:05 __db.001
-rw-r--r-- 1 root root 1318912 2008-01-18 17:05 __db.002
-rw-r--r-- 1 root root 450560 2008-01-18 17:05 __db.003
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

First step on repairing rpm database is to kill the process of the defunct and currently running rpm binary.

Proceed to repairing by killing the defunct rpm PIDs and deleting the rpm database, like so

# ps axuw | grep rpm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
root 15294 3.2 15.1 164960 /usr/bin/python /usr/bin/yum -y install whatever
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Kill the pending rpm process ID
# kill -9 15294

Delete the rpm package database files
# rm -rf /var/lib/rpm/__db.00*

Now try to do another rpm query
# rpm -qa whichever

This should fix the problem and rpm should reply with your query.

If the problem still exists, you can rebuild your rpm database by simply issuing the rpm database rebuilddb parameter like so

# rpm --rebuilddb

A more verbosed rpm database rebuild would be

# rpm -vv --rebuilddb

It would take some time though that should fix it. Then after, list out again the rpm files

# ls -la /var/lib/rpm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-rw-r--r-- 1 root root 24576 2008-01-18 17:05 __db.001
-rw-r--r-- 1 root root 1318912 2008-01-18 17:05 __db.002
-rw-r--r-- 1 root root 450560 2008-01-18 17:05 __db.003
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If all still fails, you need to do the above commands under linux single mode, which brings out another issue of rebooting your server box. Usually, the above does the trick, I never experienced booting to single mode just to have my rpm database rebuilt.

Enjoy.

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy