How to rebuild corrupted RPM database
Today I repeatedly used yum to install, update, and erase packages. It then hung for a long time during an uninstall. Wondering why it was taking so long, I checked and found that the yum process was not using any CPU. I assumed it had hung, killed it, and ran yum again. It stopped at Loaded plugins: downloadonly, fastestmirror and would not proceed. I tried again, with the same result.
Since yum hung every time, I suspected rpm. I looked for rpm processes and found one stuck with a command like this:
rpmq -q --all
I then ran an rpm command to confirm the cause, and rpm hung too. I suspected that the RPM database had crashed, so I removed its database files and rebuilt it as follows: Remove the __db.* files from /var/lib/rpm/ using:
[root@ezylinux ~]# rm /var/lib/rpm/__db.*
Rebuild the database with:
[root@ezylinux ~]# rpm --verifydb
After that, yum worked normally again.