Improve database rebuilding.