Ansible Role linuxfabrik.lfops.rpm¶
This role checks that the RPM database can be read, before any package task depends on it. A damaged database otherwise makes the first package task of a later role abort with rpmdb open failed and no hint at the cause. The setup_basic playbook runs it first on every host; on Debian and Ubuntu, it does nothing.
Available in the next LFOps release.
How the Role Behaves¶
- The role runs
rpm --verifydbandrpm --query rpm, which only read the database, also in check mode. While another rpm or dnf transaction runs, it waits for up to 5 minutes. For the momentrpm --verifydbholds the transaction lock, an rpm or dnf transaction started outside a terminal, for example by dnf-automatic, fails withcan't create transaction lockand has to run again. - If
rpm --verifydbfinds a damaged file, the run aborts. The role never runsrpm --rebuilddb, since that drops the packages it cannot read from the database without an error, see "Troubleshooting". - If the files are intact but rpm still cannot open the database, as on RHEL 8 after an rpm process got killed (
DB_RUNRECOVERY: Fatal error, run database recovery), the Berkeley DB environment in/var/lib/rpm/__db.*is broken. The role removes these files after checking that no process uses them, as Red Hat's solution 6903 describes, and rpm creates them again on its next call, with all packages kept. If a process still uses them, the run aborts and names the process instead.
Tags¶
rpm
- Checks the RPM database and, on RHEL 8, removes a broken Berkeley DB environment.
- Triggers: none.
Troubleshooting¶
The run aborts with rpm: The RPM database in /var/lib/rpm is damaged
- Copy the database directory before you change anything, for example
cp --archive /var/lib/rpm /root/rpmdb-backup(on RHEL 10, the directory is/usr/lib/sysimage/rpm). - Follow Red Hat's procedure: How to rebuild RPM database on a Red Hat Enterprise Linux system? for RHEL 8, which rebuilds the
Packagesfile withrpmdb_dumpandrpmdb_loadand then runsrpm --rebuilddb, and SQLite RPM database in Red Hat Enterprise Linux 9 and later, which runsrpm --rebuilddbor exports and imports the database withrpmdb --exportdb/rpmdb --importdb. Each of these steps drops the packages it cannot read without an error, andrpm --verifydbpasses afterwards. - Afterwards, compare
rpm --query --allwith the packages in/var/log/dnf.rpm.logor on a host installed the same way. Install the missing packages again withdnf install, or register them without touching their files withrpm --install --justdb, as Red Hat suggests. Import missinggpg-pubkeyentries withrpm --import.
The run aborts with has held the RPM database ... for more than 5 minutes
- An rpm or dnf transaction is still running, for example a large update. Check it with
ps -C rpm,dnf,dnf-automatic,yum -o pid,etime,args, and run the role again once it has finished.
The run aborts with these processes still use it
- Usually a dnf or rpm process that hangs. Check it with
ps -p <pid>, end it, and run the role again. rpm postponesSIGTERMwhile it holds the database open, so a process that hangs may needkill -KILL <pid>.