Optimize and reset database