On a heavily abused wallet.dat sometimes things become glitchy. So I came up with a script to dumpwallet to a text file, export addresses with a balance and match up against the dumpwallet, and create a cleaned.txt file of only addresses with a balance to importwallet into a brand new wallet.dat. My most glitchy wallet.dat was brought down from 154mb to 16mb, and ran very smooth.
Like usual backup wallet.dat to a safe location before messing around with anything. Hope it helps someone, should be usable on any Bitcoin fork.
https://gist.github.com/buzzkillb/b65f4520ef4d2420a168335219c13437Great script and very clear and detailed instructions in the bash file (that part of unplugging internet while dumping to avoid being hacked is a nice reminder, thanks)