How do I prune mdl_log table?

Re: How do I prune mdl_log table?

by Mark Sharp -
Number of replies: 0
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

One of the things I do is to create an archive log table for each academic year, and do a select on the log table copying those entries to the new archive log table, then deleting those entries from the original.

So, something along these lines:

CREATE TABLE mdl_logstore_standard_log_2014 AS SELECT * FROM mdl_logstore_standard_log WHERE timecreated < 1441065600 AND timecreated > 1409529600;

This will create a new table with the logs from 1st Sept 2014 to 1st Sept 2015. Then you just delete those entries from the original log table:

DELETE FROM mdl_logstore_standard_log WHERE timecreated < 1441065600 AND timecreated > 1409529600;

The new archive table won't be accessible from within Moodle, but you'll still be able to query it. And you're probably going to want to keep log tables in the future as Learning Analytics gets more important.

If you're using MariaDB another thing you may have access to is partitioned tables. This will allow you to partition tables automatically. I've not tried it yet, but it's definitely something I'm looking at. https://mariadb.com/kb/en/mariadb/partitioning-overview/

Average of ratings: Useful (3)