How to keep a moodle database clean and trim

August 22, 2011
By

If your database is becoming very large

“Help, my moodle database is huge!”

How to delete old records in a huge moodle database
How to clean moodle database tables.
How to keep a moodle database clean and trimmed
How to delete old log table records from a moodle database


For example, we cleared a 500+ meg(!) mdl_event table … moodle does not use it. It is just another history log

“Moodle keeps extensive logs of user activity. Eventually, however, the logs will become so large that they begin to clog your server. Limiting the length of time logs are kept for will reduce database table size.
“In Moodle 1.9 onwards, history tracking of changes in grades-related tables may be disabled by checking the disablegradehistory box.
“In Moodle 1.9 onwards, the length of time that the history of changes in grade-related tables is kept may be set (from 30 days to never).
“You may delete all entries (logs) from table mdl_log”
- moodle docs

Keep the number of records in these tables trimmed down

mdl_log,   mdl_event   mdl_cache_text   mdl_sessions2  

“… our moodle installation was getting extremely slow. Upon further inspection it was traced to the database which was reaching 99% cpu every time someone was hitting a course page. The reason being our mdl_cache_text table had slowly grown to over 1 million entries! … I noticed in cron.php there is a section to clear it. … do they just expect us to notice this table once it grows to an enormous size and bring the entire moodle system to its knees?” – by Etan, moodle forum
“Hello Etan,
I have exactly the same problem mentioned by you. I had no option but to empty the table manually. In less than 24 hrs. of my clearing the table manually, it has grown to almost 2 MB.” – by Manish, moodle forum

“I’ve noticed that two tables ( mdl_sessions2 and mdl_backup_log ) amount to half of the space in the Moodle database. Each of them take about 100MB of space.
I’m wondering if it is safe to flush them “manually” every now and then? I checked if there is an option inside Moodle that does this on some reg

3-28-2011
mdl_event table
I found 550+ megs, 1.6 million records, of (several years) old “event” information, (in moodle database, in mdl_event table) opening and closing of lessons events, since we first started usning moodle! Searched google. Not being used by moodle. I cleared production down to the last 10,000 records. Completely cleared it on our test site. Both are running fine. Later I cleared it completely in production. (soon, I will add a command to our backups to keep it clear.)

Comments are closed.