Professional Documents
Culture Documents
The partition of Moodle's log table (usually mdl_log) is a solution for its growth in large
sites.
Recall that in this table, Moodle includes a lot of user activities, like login or logout, file
upload, course view, consult to course's resources, and so on.
This partitioning facilitates the maintenance of this table without affecting performance
of the database or force us to modify any script of Moodle source code.
To do possible this system it is essential that the database management system, allow
make tables "daughters" from a table "mother."
Here's an example with the database manager postgres (http://www.postgresql.org/).
Steps
1. Create tables "daughters" from the table "mother" mdl_log, by "time" field, a
table for each month. In each child table we create the same constraints and
indexes (under another name) that has the table "mother".
The intervals of field "time" by months as:
1 of the month and year from 00:00:00 until the last day of the month and year of
23:59:59.
Remember that time is saved in Moodle in timestamp with gmt's date and time
format.
NOTE: these values of "time" should not be overlap from a "daugther" table to
another because it will create problems if one interval is included in two different
tables.
For example, to create the "daugther" table for January 2010 would:
2. Then create the function that will distribute the records to insert into the
"mother" table to the corresponding "daugther" table depending "time" value.
NOTE: Is very important that values of the field "time" that we have in the CHECK
statement when creating "daughter" table correspond exactly in function.
For example, to create a function that distributes the records of the first 5 months
of 2010 the function would be:
3. Now we have to create the trigger associated with the "mother" table mdl_log.
The trigger will call the previous function that distributes the records that are
destined for the "mother" table into "daughters" tables and indicates that not
save any record in the "mother" table (executing the RETURN NULL statement).
This means that the "mother" table will have always 0 entries.
If not we put the RETURN NULL statement "would get" the opposite effect we want
with the partitioning. that means to double the size of the mdl_log table.
The trigger must be set to run before (BEFORE order) insert record in "mother"
table and for each record (FOR EACH ROW order).
NOTE: To view the records in "mother" table should execute SELECT * FROM
mdl_log that returns all rows in "daugther" tables. To verify that "mother" table
has no records should do SELECT * FROM ONLY mdl_log and will show an
empty table.