Oh, and after it's all done, when rpm looks like it's permanently broken with errors like this:
# rpm --rebuilddb rpmdb: Program version 4.2 doesn't match environment version error: db4 error(22) from dbenv->open: Invalid argument error: cannot open Packages index #
The solution is: # cd /var/lib/rpm # rm __* # rpm --rebuilddb
Thank heavens for Google, and that pasting error messages into it is the fastest way to get help.