Instead of deleting useful Moodle's log data or grade book history, use this plugin to archive old data to different tables in the database.
- Place this plugin under 
localdirectory in your Moodle installation and rename it toarchiveup, e.g.moodle/local/archiveup - Log into Moodle as administrator and visit the 'Notifications' page. Follow instruction to install plugin.