Quiz throws database error

Quiz throws database error

by Alan Streeter -
Number of replies: 3

An instructor created a quiz, and when you try to take the quiz it goes to an error page. Duplicating the quiz will also give that error. I did a backup of the course on the production Moodle and recovered it on our development Moodle to test. It gives an error page on the development Moodle as well. This quiz is only one multiple choice question, the only quiz having this issue, and it happens regardless of user. I have attempted to perform a "health check" from <moodle site>/admin/tool/health, but that does not seem to be an option on our version. The version information and error page with debugging information is below. Any help is appreciated.


Our max_allowed_packet = 512M

Our max_execution_time = 600


OS: Ubuntu 17.10

Web serverApache/2.4.27

Database: MySQL 5.7.20

PHP: 7.1.8

Moodle: 3.4.4+ (production) and 3.4 (development)


Warning: mysqli::query(): MySQL server has gone away in /srv/www/public.com/public/moodle34-2017111304.08/lib/dml/mysqli_native_moodle_database.php on line 1327

Warning: mysqli::query(): Error reading result set's header in /srv/www/public.com/public/moodle34-2017111304.08/lib/dml/mysqli_native_moodle_database.php on line 1327

Error writing to database
Debug info: MySQL server has gone away
INSERT INTO mdl_question_attempt_steps (questionattemptid,sequencenumber,state,fraction,timecreated,userid) VALUES(?,?,?,?,?,?)
[array (
0 => 14134347,
1 => 0,
2 => 'todo',
3 => NULL,
4 => 1537983288,
5 => '2',
)]
Error code: dmlwriteexception
Stack trace:
  • line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 1329 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1375 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
  • line 227 of /question/engine/datalib.php: call to mysqli_native_moodle_database->insert_record()
  • line 148 of /question/engine/datalib.php: call to question_engine_data_mapper->insert_question_attempt_step()
  • line 100 of /question/engine/datalib.php: call to question_engine_data_mapper->insert_question_attempt()
  • line 100 of /question/engine/lib.php: call to question_engine_data_mapper->insert_questions_usage_by_activity()
  • line 120 of /question/preview.php: call to question_engine::save_questions_usage_by_activity()
Error reading from database
Debug info: MySQL server has gone away
SELECT * FROM mdl_course_categories WHERE id = ?
[array (
0 => '1',
)]
Error code: dmlreadexception
Stack trace:
  • line 486 of /lib/dml/moodle_database.php: dml_read_exception thrown
  • line 1245 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1571 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_records_sql()
  • line 1543 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
  • line 1522 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
  • line 1868 of /lib/pagelib.php: call to moodle_database->get_record()
  • line 1856 of /lib/pagelib.php: call to moodle_page->load_category()
  • line 1888 of /lib/pagelib.php: call to moodle_page->ensure_category_loaded()
  • line 472 of /lib/pagelib.php: call to moodle_page->ensure_categories_loaded()
  • line 820 of /lib/pagelib.php: call to moodle_page->magic_get_categories()
  • line 1644 of /lib/pagelib.php: call to moodle_page->__get()
  • line 1552 of /lib/pagelib.php: call to moodle_page->resolve_theme()
  • line 1844 of /lib/setuplib.php: call to moodle_page->initialise_theme_and_output()
  • line 374 of /lib/setuplib.php: call to bootstrap_renderer->__call()
  • line ? of unknownfile: call to default_exception_handler()

Average of ratings: -
In reply to Alan Streeter

Re: Quiz throws database error

by Ken Task -
Picture of Particularly helpful Moodlers

The 'MySQL Server has gone away' is generally a result of max_allowed_packet setting being to low ... 512M not enough.   Increase value times 2.   That's a guess.  You've not said how much memory server has so ...

Suggest installing MySQLTuner on development server first

https://github.com/major/MySQLTuner-perl

and run it to see what other tweaks DB server might benefit from.

'spirit of sharing', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: Quiz throws database error

by Alan Streeter -

Thanks for responding!

Our application server has 10 Gb memory, and the database server has 8 Gb memory.

I ran mysqltuner.pl on the server, so we have some recommendations from that to look at. I'm not sure any of that would affect this one quiz though.

After bumping max_allowed_packet up to 1024M, it threw a new error when I tried to take the quiz again:


    Warning: mysqli::query(): MySQL server has gone away in /srv/www/lms.kvcc.edu/public/moodle34-2017111304.08/lib/dml/mysqli_native_moodle_database.php on line 729

Warning: mysqli::query(): Error reading result set's header in /srv/www/lms.kvcc.edu/public/moodle34-2017111304.08/lib/dml/mysqli_native_moodle_database.php on line 729
Table "question_attempt_steps" does not exist
Debug info:
Error code: ddltablenotexist
Stack trace:

    line 1359 of /lib/dml/mysqli_native_moodle_database.php: dml_exception thrown
    line 227 of /question/engine/datalib.php: call to mysqli_native_moodle_database->insert_record()
    line 148 of /question/engine/datalib.php: call to question_engine_data_mapper->insert_question_attempt_step()
    line 100 of /question/engine/datalib.php: call to question_engine_data_mapper->insert_question_attempt()
    line 100 of /question/engine/lib.php: call to question_engine_data_mapper->insert_questions_usage_by_activity()
    line 349 of /mod/quiz/locallib.php: call to question_engine::save_questions_usage_by_activity()
    line 2387 of /mod/quiz/locallib.php: call to quiz_attempt_save_started()
    line 111 of /mod/quiz/startattempt.php: call to quiz_prepare_and_start_new_attempt()

Error reading from database
Debug info: MySQL server has gone away
SELECT * FROM mdl_course_categories WHERE id = ?
[array (
0 => '1',
)]
Error code: dmlreadexception
Stack trace:

    line 486 of /lib/dml/moodle_database.php: dml_read_exception thrown
    line 1245 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
    line 1571 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_records_sql()
    line 1543 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
    line 1522 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
    line 1868 of /lib/pagelib.php: call to moodle_database->get_record()
    line 1856 of /lib/pagelib.php: call to moodle_page->load_category()
    line 1888 of /lib/pagelib.php: call to moodle_page->ensure_category_loaded()
    line 472 of /lib/pagelib.php: call to moodle_page->ensure_categories_loaded()
    line 820 of /lib/pagelib.php: call to moodle_page->magic_get_categories()
    line 1644 of /lib/pagelib.php: call to moodle_page->__get()
    line 1552 of /lib/pagelib.php: call to moodle_page->resolve_theme()
    line 1844 of /lib/setuplib.php: call to moodle_page->initialise_theme_and_output()
    line 374 of /lib/setuplib.php: call to bootstrap_renderer->__call()
    line ? of unknownfile: call to default_exception_handler()

In reply to Alan Streeter

Re: Quiz throws database error

by Mabry Wilkinson -

I work with Alan and wanted to provide some follow up to our error. The error seems to stem from some of the Moodle code. In our config.php there is a variable "$CFG->prefix='mdl_' along with other variables necessary for the database to accept calls such as "dbuser" and "dbname" etc. While following our trace stack it appears that the error thrown, at least for the write error, is not getting that prefix appended for our db table name (question_attempt_steps). I believe that is why it is saying "Table does not exist." This issue is an interesting one as we are not running into this issue anywhere else.