The RPM database is held in /var/lib/rpm . If it gets damaged it can be rebuilt using the following procedure (first posted to the linux.redhat.rpm newsgroup by Brian Ollenberger)
#!/bin/bash
#rpmdel: (C)2001 Brian Ollenberger
rm -f rpmdel.log
echo "Listing packages..."
for i in `rpm -qa --queryformat %{NAME}'\n'`
do
FILEMISSING=`rpm -V $i | sed s/"missing "//g | grep "^/" -c`
if [ $FILEMISSING -gt 0 ]
then
TOTALFILES=`rpm -q --filesbypkg $i | grep "" -c`
if [ $FILEMISSING -eq $TOTALFILES ] #no files - delete package from db
then
rpm --justdb --nodeps -e $i
if [ $? -eq 0 ]
then
echo "$i" >> rpmdel.log
else
echo "An error occured deleting package $i."
fi
elif [ $FILEMISSING -lt $TOTALFILES ] #partially missing
then
echo "Package $i is missing some of its files."
else #THIS SHOULD NOT RUN
echo "*Package $i is missing more files than it should have."
echo "* This should NOT happen. Check this package carefully."
fi
fi
done