rpm-guide rpm-guide-using-rpm-db-en.xml,NONE,1.1
Stuart Ellis (elliss)
fedora-docs-commits at redhat.com
Tue Oct 4 02:07:28 UTC 2005
Author: elliss
Update of /cvs/docs/rpm-guide
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv2533
Added Files:
rpm-guide-using-rpm-db-en.xml
Log Message:
--- NEW FILE rpm-guide-using-rpm-db-en.xml ---
<!-- $Id: -->
<chapter id="ch-using-rpm-db">
<title>Using the RPM Database</title>
<para>
In This Chapter
</para>
<para>
*Querying the RPM database
</para>
<para>
*Getting information on RPM files
</para>
<para>
* Finding out which packages own files on your system
</para>
<para>
* Verifying installed packages
</para>
<para>
*Backing up the RPM database
</para>
<para>
*Repairing damaged RPM databases
</para>
<para>
Every package you install with RPM is recorded in the RPM database.
The RPM system includes commands to query this database to find out
which packages are installed and to provide quite a few details
about these packages.
</para>
<para>
This chapter covers querying both the RPM database and RPM package
files. Both types of query are important:
</para>
<para>
*Query the RPM database to see what is installed, or not installed,
on your system.
</para>
<para>
*Query package files to see what the files require, as well as what
the files provide.
</para>
<para>
In addition to querying the RPM database, you can use the database
to verify packages. Since this database is so important to the
management of your Linux system, this chapter covers how to back it
up, as well as how to repair a damaged RPM database.
</para>
<sect1>
<title>Querying the RPM Database</title>
<para>
In Chapter 4, you saw that the rpm command usually takes one major
command-line option to tell it the operation to perform and a
myriad of command-line options to customize the operation. The rpm
command may also take the name of one or more RPM package files or
the name of one or more installed packages. For example, the rpm
âi command performs an installation operation, and the rpm âU
command performs an upgrade.
</para>
<para>
For querying the RPM database, the major command-line option is
âq, short for query. This option tells the rpm command to query
the RPM database. You can also use the long option --query.
</para>
<para>
In the last few chapters, you've used the âq option with the rpm
command to query just for the presence or absence of installed
packages. You can expand the -q option to perform a wide array of
queries to find out information about the packages installed on a
Linux system.
</para>
<sect2>
<title>Querying packages</title>
<para>
The basic format of the rpm âq command follows:
</para>
<para>
rpm âq package_name
</para>
<para>
You need to provide the name of a package to query. For example:
</para>
<para>
rpm -q telnet-0.17
</para>
<para>
This command returns the name of the package, if installed. For
example:
</para>
<para>
telnet-0.17-20
</para>
<para>
If the package is not installed, youâll see a message like the
following:
</para>
<para>
package telnet-0.17 is not installed
</para>
<para>
You can provide the whole package name to the rpm command, which
includes the name, the version, and the RPM package number, as
discussed in Chapter 3. You can also just provide the name and
version number, as shown previously, or just the base name of
the package.
</para>
<para>
For example, the following command uses just the base name of
the package:
</para>
<para>
$ rpm -q telnet
</para>
<para>
telnet-0.17-20
</para>
<para>
Note
</para>
<para>
The rpm âq command expects a package name. Although it
supports some amount of customized queries, you really need to
know which packages you want the rpm command to report on.
</para>
<para>
You can provide more than one package name; the rpm command
reports on each package, as shown following.
</para>
<para>
$ rpm -q telnet telnet-server
</para>
<para>
telnet-0.17-20
</para>
<para>
telnet-server-0.17-20
</para>
<para/>
<para>
You need to change the way you query if you want to perform
searches when you do not know the full package name in advance.
The following sections cover options for creating various
queries.
</para>
</sect2>
<sect2>
<title>Querying everything</title>
<para>
Up to now, we have used the rpm command to query only for
specific packages. The âa option tells the rpm command to
query for all packages. You can also use the longer option,
--all, in place of âa.
</para>
<para>
For example:
</para>
<para>
rpm -qa
</para>
<para>
This command returns every package installed on your system,
quite a few packages. The packages are returned one per line, as
shown following.
</para>
<para>
words-2-17
</para>
<para>
kudzu-0.99.23-1
</para>
<para>
openldap-2.0.11-13
</para>
<para>
rpm-4.0.3-1.03
</para>
<para>
kernel-smp-2.4.7-10
</para>
<para>
quota-3.01pre9-3
</para>
<para>
expat-1.95.1-7
</para>
<para>
[...4111 lines suppressed...]
</para>
<para>
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.
</para>
<para>
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.
</para>
<para>
The RPM database is really a number of Berkeley DB databases, each
designed for a different type of query.
</para>
<para>
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.
</para>
<para/>
<sect2>
<title>Backing up the RPM database</title>
<para>
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:
</para>
<para>
# cd /var/lib
</para>
<para>
# tar cvf rpmdb.tar ./rpm
</para>
<para>
# gzip rpmdb.tar
</para>
<para>
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.
</para>
<para>
Note
</para>
<para>
Adding the z option to the tar command can create a compressed
archive directly, without the need for the gzip command.
</para>
</sect2>
<sect2>
<title>Rebuilding the RPM database</title>
<para>
If the RPM database has been corrupted in some way, you can use
the --rebuilddb option to tell the rpm command to rebuild your
database.
</para>
<para>
For example:
</para>
<para>
rpm --rebuilddb
</para>
<para>
This command rebuilds the RPM database from the installed
packages, the file named Packages in the /var/lib/rpm directory.
Only the Packages file is required. All the other files can be
recreated from the Packages file. If your database is OK, this
command won't do much, other than shrink the size of your RPM
database by removing unused entries. This command will take some
time to execute, though.
</para>
<para>
Warning
</para>
<para>
Before running this command, back up your RPM database.
</para>
<para>
To check that the rpm --rebuilddb command has not damaged the
RPM database, you can check with a file listing, query all
packages, and then check the results of the rpm ârebuilddb
command with another file listing when done.
</para>
<para>
Another useful technique that can help with a corrupted RPM
database is to use the db_dump and db_load utilities that come
with RPM (from the SleepyCat DB database library). Use db_dump
to dump the Packages file. Then, use db_load to reload the
Packages file. The act of dumping and restoring may fix a
corrupted file. As always, back up your RPM database prior to
performing these commands.
</para>
</sect2>
<sect2>
<title>Creating a new RPM database</title>
<para>
If all else fails, use the --initdb option to tell the rpm
command to create a new empty RPM database. In almost all cases,
you do not want to create a new RPM database, since this
database will be empty. It will not have any knowledge about the
packages you have already installed on your system. That could
lead to a lot of problems, since you have the files installed,
but the RPM system just doesnât know about them.
</para>
<para>
The basic syntax follows.
</para>
<para>
rpm --initdb
</para>
<para>
Note
</para>
<para>
This command should not damage an existing database.
</para>
<para>
If the RPM system cannot be rebuilt, you may have to reinstall
the operating system to recreate a clean system. In general, if
things are this far gone, reinstalling may be your best answer
instead of wiping the RPM database and creating an empty
database.
</para>
<para>
You can also use the --dbpath option to tell the rpm command to
create an RPM database in a different directory.
</para>
<para>
For example:
</para>
<para>
mkdir /tmp/rpm
</para>
<para>
rpm --initdb --dbpath /tmp/rpm
</para>
<para>
These commands create a temporary directory and an RPM database
in the /tmp/rpm directory.
</para>
<para>
After running this command, you can examine the files created.
</para>
<para>
# ls -l /tmp/rpm
</para>
<para>
total 288
</para>
<para>
-rw-r--r-- 1 root root 8192 Oct 10 20:29 __db.001
</para>
<para>
-rw-r--r-- 1 root root 1310720 Oct 10 20:29 __db.002
</para>
<para>
-rw-r--r-- 1 root root 360448 Oct 10 20:29 __db.003
</para>
<para>
-rw-r--r-- 1 root root 12288 Oct 10 20:29 Packages
</para>
<para>
This shows an empty RPM database.
</para>
</sect2>
</sect1>
<sect1>
<title>Summary</title>
<para>
This chapter covers the rpm command options to query the RPM
database and RPM package files. You can determine the packages
installed on your system, as well as which packages are
responsible for the files on your system.
</para>
<para>
The RPM database maintains a lot of information about the files
and packages on your system. Thus, it is crucial for managing your
Linux systems. You should back up the RPM database before and
after any installation, upgrade, or removal of packages.
</para>
<para>
You can also use the --rebuilddb option to the rpm command to
rebuild a damaged RPM database.
</para>
</sect1>
</chapter>
<!--
Local variables:
mode: xml
sgml-parent-document:("rpm-guide-en.xml" "book" "chapter")
fill-column: 72
End:
-->
More information about the Fedora-docs-commits
mailing list