Solution for moodle statistic problem. moodle统计出错解决方案

Sometime moodle statistic doesn’t work properly. It return an error like this:

Statistics is currently in catchup mode. So far 1 day(s) have been processed and 21 are pending. 

It is a very tricky problem. Following solution is from Christopher Lawrence. It done miracles for many people.

I have to respond to this one because I too when through this problem for weeks and I finally got it working since my testing. I feel your pain and hopefully I can help everyone who is encountering the same weird anomaly

Here is what I have done.

1. If you can, first, upgrade your Moodle just in case. The stats query is problematic and could time out. FYI, I did not upgrade so that should ease your mind (I’m running 1.9.2). I heard it was somewhat fixed in 1.9.4 weekly build.

2. If you can, do a DB check on your mdl_stats table to make sure the statistic tables are working properly.

CHECK TABLE `mdl_stats_daily` , `mdl_stats_monthly` , `mdl_stats_user_daily` , `mdl_stats_user_monthly` , `mdl_stats_user_weekly` , `mdl_stats_weekly` , `mdl_log`

You should get something like:

mdl_stats_daily check status OK
mdl_stats_monthly check status OK
mdl_stats_user_daily check status OK
mdl_stats_user_monthly check status OK
mdl_stats_user_weekly check status OK
mdl_stats_weekly check status OK
mdl_log check status OK

3. if there there are errors, reindex/repair the tables or better yet, your entire database based on your index type (MyISAM or InnoDB)

4. Have a look at you config table and if you can reset the values for statsfirstrunlock, statslastdaily, statsruntimestarthour, and statsruntimestarminute to 0. This will force it to start from the beginning. Note that it could take a while depending on how far back your log starts to process the stats (statsfirstrun field). The values are unix/linux timestamp. Here is a page that I have found useful to calculate the dates in human friendly display. Just enter the datetime stamp values:

http://www.onlineconversion.com/unix_time.htm

5. Have a look at your stats admin page and check and uncheck a few times the “include stats” option.

6. Return to your stats admin page and see when the stats is scheduled to run and make a note of it. It’s misleading because it does not run at that time you set but rather it runs on the NEXT cron call AFTER THE SCHEDULED DATE you entered. For example if you set your stats to run at 1:30 AM, it won’t run at 1:30 AM as you think it should but instead it runs at the next cron call. Now get this, it does not call on the stats to run everytime so it adds more confusion. It only runs randomly and only within an allowable timeframe o it won’t take a lot of server processes. Clear as mud? =)

To save everyone’s time, let me show you my cron process (assuming that I have the stats schedule to run at 1:30 AM). I do a back up first using MySQL dump just in case.

10 0 * * * mysqldump -u root -pYourPassword –databases yourMoodleDB > /backup/backupMoodle19/yourMoodlebackup.sql
11 1 * * * /usr/bin/php /usr/var/www/moodle/admin/cron.php > /yourHome/name/checklogA.txt
03 2 * * * /usr/bin/php /usr/var/www/moodle/admin/cron.php > /yourHome/name/checklogB.txt

Explanation:

Assumption: Stats scheduled at: 1:30 AM

1. At 12:10 AM, Linux cron executes the MySQL mysqldump program to backup the moodle database) as mysql root user to the /backup/backupMoodle19/ folder as: yourMoodlebackup.sql

2. At 1:11 AM, the Linux cron calls the moodle cron.php script located locally in the server in /usr/var/www/moodle/admin folder and results logged in a text file called checklogA.txt in the user’s home directory (/yourHome/name). It is at this call that the stats process should be scheduled and executed at the next cron call (next step number 3).

2. At 2:03 AM, the Linux cron calls the moodle cron.php script a second time located locally in the server in usr/var/www/moodle/admin folder and results logged in a text file called checklogB.txt in the user’se directory (/yourHome/name). It is at this call that the stats process should start executing/building! The log file should tell you that. It’s the same as when you see it scroll onscreen via command line.

I hope this helps everyone.

Good luck.

Christopher

[ 2010-6-3 ]补充
重新运行cron.php,当出现: “…preventing stats to run, last execution was less than 20 hours ago.”时
把config表中statslastexecution值设为0。这样就可以正常的重新运行cron了。

发表评论

电子邮件地址不会被公开。

Time limit is exhausted. Please reload CAPTCHA.