• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to recover from a corrupt RPM database (rebuilding an RPM database)

by admin

Why rpm database gets corrupted

There can be multiple reasons which can lead to rpm database corruption. One can not exactly pinpoint a single RCA for that because of the limitations, there is no mechanism to monitor rpm database corruption.

– rpm database gets queried every time Administrator/some process run any rpm command.
– Even during yum transactions, rpm database is altered heavily.
– A small pointer can also cause such corruption.
– If LD_LIBRARY_PATH is set to some value, even rpm database corrupts.
– If any third party package is installed which causes un-necessary changes in rpm database.
– Incomplete transactions too can lead to such corruptions.
– In case of /var partition located on SAN volumes.

So in total, lots of factors can be considered for such rpm database corruption. If rpm database goes corrupt frequently, it’s recommended to take backup of RPM database frequently via cron.

Repair the RPM database

The RPM tool uses its own custom database implementation to contain its information. Sometimes that database can get corrupted; symptoms include claims that an installed RPM package is missing; or attempts to update an RPM simply hang. Attempts to query (rpm -q) some packages may fail with below error.

rpmdb: /var/lib/rpm/Packages: unexpected file type or format  
error: cannot open Packages index using db3 - Invalid argument (22)

If your RPM database is hung or corrupted you can try to repair it with these commands. Please note: This process is not guaranteed to work. You must be logged in with superuser privilege (aka “root”) for these steps. The commands may be copied and pasted directly into a root terminal window.

1. Make sure there are no RPM processes left running on your system. Use the ps command to identify them. Use the kill command to terminate any “rpm” processes you find; a “kill -9” may be necessary.

# ps -ef | grep-i rpm

2. Delete the lock files that RPM uses:

# rm -f /var/lib/rpm/__db*
# /usr/lib/rpm/rpmdb_verify /var/lib/rpm/Packages

3. If you were experiencing a hanging “rpm” command, try it again. If it works, you are finished. If not, perform Step #1 and #2 again. Then proceed to the next step.

4. Make a backup of your RPM database:

# cd /var/lib
# mkdir rpm-backup
# rsync -av ./rpm/. ./rpm-backup/.

5. Rebuild your RPM database:

# rpm -vv --rebuilddb > /tmp/rpmrebuilddb.log 2>&1

6. Try verifying the rpm database again.

# cd /var/lib/rpm
# /usr/lib/rpm/rpmdb_verify Packages
Note: If the above recovery steps fail or throw errors, restoring /var/lib/rpm directory from a recent system backup may be your best option. Remember to not overwrite the tar backup as it may still be valuable.

6. Retry your failed RPM command.

RPM command examples to query, install, remove and upgrade packages

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. ping Command Examples in Linux
  2. How to work with multiple java versions under Linux
  3. hdparm Command Examples in Linux
  4. crontab Command Examples in Linux
  5. How to modify snmp service to listen to an alternative port in CentOS/RHEL
  6. atop: command not found
  7. How to configure LDAP Client on CentOS/RHEL 6 using SSSD
  8. conntrack: command not found
  9. What is the purpose of .bash_profile file under User Home Directory In Linux
  10. kill Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • qsub Command Examples in Linux
  • qsub: command not found
  • qrcp Command Examples in Linux
  • qmrestore Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright