How to detect and rebuild a corrupt RPM database quickly and safely from the command line. 16.11.2025 | reading time: 2 min The RPM package database can become corrupt and block all package operations; this guide shows how he can detect the symptoms and perform a safe rebuild with concrete commands. Recognizing the failure Show the symptom first by invoking an operation that reads the DB; common failure looks like this: ```bash # rpm -qa error: db5 error while opening file /var/lib/rpm/Packages: BDB0002 DB_RUNRECOVERY: Fatal error, run database recovery ``` This proves the DB is inconsistent and needs repair. Back up and rebuild sequence Tell, then do: back up the DB, remove Berkeley DB journal files if present, then rebuild; for example: ```bash # cp -a /var/lib/rpm /root/rpm-backup-2025-11-16 # rm -f /var/lib/rpm/__db* # rpm --rebuilddb # rpm -qa | head ``` He should run these as root and verify `rpm -qa` returns packages again. Permissions, SELinux and alternatives If problems persist check ownership and SELinux context, for example run `chown -R root:root /var/lib/rpm` and `restorecon -Rv /var/lib/rpm`; on some systems `rpmdb --rebuilddb` is available as an alternative, and `db_dump` can be used to extract records if recovery is required. Verify and follow up After rebuild, verify package integrity with `rpm -Va` and then run the higher-level package manager update or transaction; if packages are missing or headers are damaged he can reinstall packages from the distro repos or use the backup made earlier. When to escalate If database headers are corrupted beyond rebuild, use `db_dump`/`db_load` to salvage, restore from backups, or boot into rescue media to repair the filesystem; always avoid concurrent package manager processes during repair. Wrap-up and next steps A rebuilt RPM DB brings package management back to life; practice this procedure in a VM and include DB backups in your recovery plan to avoid surprises—consider certification paths to deepen skills, for example CompTIA Linux+ or LPIC-1, and use bitsandbytes.academy for intensive exam preparation. Join Bits & Bytes Academy First class LINUX exam preparation. utilities troubleshooting backup