If your rpm database gets corrupt, you receive the following message on working on packages using rpm:

rpmdb: unable to join the environment
rpmdb: write: 0xbf91a7d0, 8192: Invalid argument
error: db4 error(22) from dbenv->open: Invalid argument
error: cannot open Packages index

You can try out any of the following two solutions:
rm -f /var/lib/rpm/__db*
rpm –rebuilddb


2. you need to add the following ‘export’ line in /etc/profile file and rebuild the database.
export LD_ASSUME_KERNEL=2.2.5 (2.2.5 is the base kernel)
rpm –rebuilddb

With the second solution, the changes will take effect on the next session.} else {