This page has lots of useful information if you’re using Red Hat and are a fan of Gnome. It also has the following very valuable nugget of information:
RPM is a little buggy imho (well, at least on rpm 4.1). Sometimes (randomly), rpm will lock up halfway through a query or package install.
The best solution is to open a new terminal as root and perform a killall -9 rpm or killall -9 rpmq (depending on whether you’re installing or querying). Then you need to remove the stale lock files with rm -f /var/lib/rpm/__db.00*. You should then have regained control of rpm.