Product SiteDocumentation Site

4.4.3. Working With the RPM Database

As mentioned in Chapter 2, RPM Overview , the RPM database is stored in /var/lib/rpm. The files in that directory are Berkeley DB files, as shown by the file command:
      # file /var/lib/rpm/*
      /var/lib/rpm/Basenames: Berkeley DB (Hash, version 7, native byte-order)
      /var/lib/rpm/Conflictname: Berkeley DB (Hash, version 7, native byte-order)
      /var/lib/rpm/__db.001: data
      /var/lib/rpm/__db.002: X11 SNF font data, LSB first
      /var/lib/rpm/__db.003: X11 SNF font data, LSB first
      /var/lib/rpm/Dirnames: Berkeley DB (Btree, version 8, native byte-order)
      /var/lib/rpm/Filemd5s: Berkeley DB (Btree, version 8, native byte-order)
      /var/lib/rpm/Group: Berkeley DB (Hash, version 7, native byte-order)
      /var/lib/rpm/Installtid: Berkeley DB (Btree, version 8, native byte-order)
      /var/lib/rpm/Name: Berkeley DB (Hash, version 7, native byte-order)
      /var/lib/rpm/Packages: Berkeley DB (Hash, version 7, native byte-order)
      /var/lib/rpm/Providename: Berkeley DB (Hash, version 7, native byte-order)
      /var/lib/rpm/Provideversion: Berkeley DB (Btree, version 8, native byte-order)
      /var/lib/rpm/Requirename: Berkeley DB (Hash, version 7, native byte-order)
      /var/lib/rpm/Requireversion: Berkeley DB (Btree, version 8, native byte-order)
      /var/lib/rpm/Sha1header: Berkeley DB (Btree, version 8, native byte-order)
      /var/lib/rpm/Sigmd5: Berkeley DB (Btree, version 8, native byte-order)
      /var/lib/rpm/Triggername: Berkeley DB (Hash, version 7, native byte-order)
Each file is a separate database in Berkeley DB format, except for a few __db data files. (These are not really X11 font files, just plain data files. The file command is confused by the data in the files.)

The Berkeley DB Library

Available from Oracle at http://www.oracle.com/technetwork/database/berkeleydb/overview/, the Berkeley DB library provides a simple database API. This is not a traditional relational database. Instead, data values are stored in what amounts to a persistent hash table of name/value pairs. This type of database is very quick to look up a named entry (such as a package name) but is not so quick for iterating over all the entries.
The RPM database is really a number of Berkeley DB databases, each designed for a different type of query.
If something goes wrong with your RPM database, you can first try to rebuild it. If that fails, you may need to initialize a new database, although that is generally not needed. First and foremost, however, you should back up this database.

4.4.3.1. Backing up the RPM database

As mentioned before, the RPM database resides in the /var/lib/rpm. You can back up the RPM database by using a command such as the following:
tar cf rpmdb.tar /var/lib/rpm