Recreation of a corrupted RPM DB

In some cases (basically when the RPM DB has been accessed from two different jobs) the RPM DB might be corrupted. The procedure to rebuild it includes the following steps:

  • cd <ROOT_RPM>/var/lib
  • tar zcvf /var/preserve/rpmdb-`date + "%d%m%Y"` .tar.gz rpm

Verification of packages integrity

  • cd <ROOT_RPM>/var/lib/rpm
  • rm -f __db*
  • /usr/lib/rpm/rpmdb_verify Packages

If this reports any error then a dump and load of the DB is required

  • mv Packages Packages.orig
  • /usr/lib/rpm/rpmdb_dump Packages.orig | /usr/lib/rpm/rpmdb_load Packages
  • /usr/lib/rpm/rpmdb_verify Packages

Additional sanity step:

  • rpm --dbpath <DB full path> -qa 1 > /dev/null

If no errors are generated, then the DB can be rebuild:

  • rpm -v --dbpath <DB full path> --rebuilddb

You are here