Error with rpmdbnextiterator

This following problem is for rpm-based distros.

I was using CentOS on a system, and found that after a while, the rpmdb seemed to have a bit of a problem.  I noticed it when running:

yum update

and I would see a load of errors - mainly with:

error: rpmdbnextiterator: skipping h# 526  Header v3 DSA signature: BAD

followed by package details that were having problems.  I also noticed it when querying the rpm database for a package that was installed.

So what do we do?  Well, we have to take a look at and fix the system.  For me, all I had to do was this:

rpm --rebuilddb

and then everything was back to normal.  However, there are some cases, where you might need to do:

mkdir /var/lib/rpm/old
mv /var/lib/rpm/Pubkeys /var/lib/rpm/old/
rpm --rebuilddb

and that should fix it.