The RPM database on your CentOS server stores information about all installed RPM packages and resides in the /var/lib/rpm/
directory. This database is essential for managing package updates via the YUM package manager. However, the RPM database can become corrupted, which may prevent you from updating packages or executing RPM and YUM commands.
Causes of RPM Database Corruption
The RPM database may become corrupted for several reasons, including:
- Third-party software interference
- Incomplete transactions
- Network failures during package upgrades
- Removal of certain packages
If you want to pinpoint the exact cause of the corruption, you can attempt debugging. Below are methods for recovering a corrupted RPM database.
Symptoms of a Corrupted RPM Database
When the RPM database is corrupted, you might encounter errors such as:
rpm: cannot open Packages database in /var/lib/rpm
rpmdb: Lock table is out of available locker entries
rpmdb: /var/lib/rpm/Packages: unexpected file type or format
error: cannot open Packages index using db3 – Invalid argument (22)
error: rpmdbNextIterator: skipping h# 1601 Header V4 RSA/SHA1 signature: BAD, key ID 2142eef7
rpmdb: BDB0113 Thread/process 4106/140140548798528 failed: BDB1507 Thread died in Berkeley DB library
These errors typically indicate that the database is corrupted.
Solutions
Method #1
Create a backup of the RPM database:
mkdir /var/lib/rpm/backup
cp -a /var/lib/rpm/__db* /var/lib/rpm/backup/
Remove the old database files:
rm -f /var/lib/rpm/__db.[0-9][0-9]*
Rebuild the database indices from the installed package headers:
rpm --quiet -qa
rpm --rebuilddb
Clean the YUM cache:
yum clean all
Method #2
Backup the RPM database:
mkdir /backups/
tar -zcvf /backups/rpmdb-$(date +"%d%m%Y").tar.gz /var/lib/rpm
Remove stale locks and verify the integrity of the master package metadata file:
rm -f /var/lib/rpm/__db*
/usr/lib/rpm/rpmdb_verify /var/lib/rpm/Packages
If verification fails, dump and reload the database:
cd /var/lib/rpm/
mv Packages Packages.back
/usr/lib/rpm/rpmdb_dump Packages.back | /usr/lib/rpm/rpmdb_load Packages
/usr/lib/rpm/rpmdb_verify Packages
Check database headers and print errors:
rpm -qa >/dev/null # output is discarded to enable printing of errors only
Rebuild the RPM database with debugging information:
rpm -vv --rebuilddb
For a detailed guide, refer to the RPM database recovery page.
Method #3
If previous methods do not resolve the issue, try these commands:
- Move the current Packages file and rebuild the database:
mv Packages Packages-BAKUP
db_dump Packages-BAKUP | db_load Packages
rpm -qa
rpm --rebuilddb
Using dcrpm
to Identify and Correct RPM Database Issues
The dcrpm
(detect and correct rpm) tool can be used to address problems with the RPM database. It can also be scheduled to run regularly via cron.
Download and install dcrpm
:
git clone https://github.com/facebookincubator/dcrpm.git
cd dcrpm
python setup.py install
Detect any issues with RPM on your server:
dcrpm
Before using dcrpm
, check its GitHub repository for the latest updates and documentation.
We appreciate the input from our client in Toulupe, who contributed to addressing RPM database issues in our community forum and provided one of the solutions outlined above.