Updated: 28 September 2026 · Applies to: RPM 4.16 (AlmaLinux, Rocky Linux, RHEL 9) and 4.19 (version 10), SQLite package database
The RPM database records every installed package. If it is damaged, for example by a full disk or a crash during an update, rpm and dnf fail with errors such as "rpmdb open failed", "database disk image is malformed" or "error: cannot open Packages database". On CentOS 7 and older releases the database used Berkeley DB files (__db.001 and similar). On AlmaLinux, Rocky Linux and RHEL 9 and 10 it is a single SQLite file, rpmdb.sqlite, and the repair is simpler. We tested the rebuild on AlmaLinux 9.
Where the database is
- Version 9:
/var/lib/rpm/rpmdb.sqlite - Version 10:
/usr/lib/sysimage/rpm/rpmdb.sqlite;/var/lib/rpmis a link to that folder.
rpm -E %_dbpath shows the path on any system.
Steps
- Make sure no rpm or dnf process is running:
pgrep -a 'rpm|dnf|yum|packagekit'. Wait for them, or stop PackageKit withsystemctl stop packagekit. - Check the disk:
df -h /var /usr. A full disk is a common cause; free space first. - Back up the database folder:
cp -a "$(rpm -E %_dbpath)" /root/rpmdb-backup-$(date +%F)
- Check the database:
rpmdb --verifydb
No output means no problems were found. - Rebuild it from the package headers it contains:
rpmdb --rebuilddb
- Test that packages are listed again and dnf works:
rpm -qa | wc -l dnf check dnf makecache
If the rebuild fails
- "failed to replace old database with new database": the rebuilt copy is in a folder named
rpmrebuilddb.NNNNnext to the database. This happens when the database folder cannot be replaced, for example in some containers. Follow the message's advice and copy the files from that folder over the old ones, with a backup in place. - Packages are missing after the rebuild: the damaged records could not be recovered. Reinstall the affected packages with
dnf reinstall;rpm -Vahelps to find files that no package claims. - Nothing helps: restore the database folder from a system backup taken before the problem.
Official documentation: RPM documentation and rpmdb manual page.
Ucartz services for this topic
- KVM VPS hosting: NVMe SSD and full root access, with Free Basic Managed Support.
- Unmanaged dedicated servers: full root access and free IPMI KVM, with Free Basic Managed Support.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
