Product SiteDocumentation Site

4.5. 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 SleepyCat Software at www.sleepycat.com/, 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.
One of the nice things about this library is that it is available in an open-source format, and you can get programming API libraries for C, C++, Java, Python, Perl, and Tcl languages.
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.5.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 commands such as the following:
# cd /var/lib
# tar cvf rpmdb.tar ./rpm
# gzip rpmdb.tar
These commands create a tar archive from the contents of the rpm directory (where the RPM database is stored) and compress the file with the gzip command.
Note
Adding the z option to the tar command can create a compressed archive directly, without the need for the gzip command.