A disclaimer first:
> Currently, we do not really know what else to look for. We use
Postgres, by the way.
I assume that you are talking to the large community. AFAIC, consider me as another patient in the same clinic who has a history of the same symptoms, knows them "from inside". But that doesn't make him a doctor! He talks from the prescriptions he received, mostly just recollections, always centered on his particular case. That is not what we want.
> Quizzes are used extensively in only one course. While they do exist in other courses, only this particular course contains a large number of questions and quizzes. It is possible that no one has ever attempted to copy a quiz in any other course.
It could be just the size, or broken data due unfinished transactions. Probably both. Then you should ask, "Why the size"? The easiest explanation is that the now infamous feature/bug has started duplicating question categories and triggered a vicious circle. If that is true, patching the but is not enough, one has to clean the (data) mess! That is only possible with a deep understanding of the database model and being able to identify the bloat - likely what only Moodle makers know. A commercial contract to a Moodle Partner could be the sensible solution, if your organization is big. It sounds like Microsoft selling virus cleaners for Windows, but that was a thing.
>> Is it the only course that makes use of a large collection of question categories?
>
> Yes
See above.
>> And consequently contains large number of duplicated categories?
>
> I wouldn't say so. I see about 40 categories in the question bank for this course. Most of them seem to contain questions. However, all of them have names that were apparently chosen by the teacher. There's nothing like "My category (copy)", for example.
Interesting. Most of our duplicated categories have "(Kopie)" in their names. Can you vow to the fact all the questions in that course are unique (the versions not counting)?
>> Is it a "forever course"? People come and take exams and go, the course remains - with all the user data, most importantly the exam results?
>
> Yes, it is an ongoing course that is updated once a year.
Do you reset the course yearly? Then it is not a "forever course" in my jargon. The forever courses happen because the institutions are supposed to archive exam results five years, for example. Therefore you'll find which have past exam submission spanning five year or more. (_More_ because nobody thinks of cleaning them - they trust the Moodle admin to be an archiver and historian.)
>> Do you duplicate a few quizzes each time?
>
> I can at least say the teacher duplicated quizzes in 2025 (Moodle 4.2; no problems) and again in 2026 (Moodle 4.5; huge problems).
Well, they might be having exam seasons tied to the semesters. If my theory above is correct, i.e. the course continuously accumulate questions, then one day it overflows - without an apparent major incident.
>> Do they get their questions randomly from question categories?
>
> No. The teacher would like to use this feature but has had problems in the past. In some cases, no suitable question could be found. She did not use this feature for the 2025 or 2026 quizzes.
If you say, the many questions are unique and quizzes were not fetching questions randomly, I am possibly following a red herring.
>> How many versions your questions have on average?
>
> About four, but very few questions have many versions (up to 43).
>
>> Are your quizzes set always to take the latest version?
>
> I think so. In mdl_question_references, version is always NULL.
OK. I don't know how relevant the number is. But at least AFAIC, they add another layer of (unwelcome) complications.
>> If you can make it run on the CLI, that might release the blockade.
>
> I tried to duplicate a quiz using the CLI with sudo php import.php --srccmid= --dstcourseid=, but it didn't work. The process hasn't finished even two hours later. It caused a huge amount of DB queries like the ones I mentioned in my original post.
That is not good. Something is brocken: either the DB has become too big for the machine, or the data has anomalies or just a bug.
Talking of the DB how big is a
SQL dump? What is the size of the DB reported by the DBMS? How much RAM do you give the DB?
>> The huge
database queries sound like Moodle is wanting to back up huge amount of data in to the database and getting timed out. I would dive in to that. Why? What data?
>
> We removed all questions that had no entry in mdl_question_references, as well as entries in mdl_files that had component 'question', but were not linked to a question.
As said earlier, there were many receipe to make the DB leaner. The above is just one. See those long discussions I've linked in my previous reply for more. Again, I can't definitely say which one would help, which ones will cause more trouble.
I'm at my wits' end. Remember, no doctor here. Hope, qualified people will come to help.
Edit: You checked the obvious, monitoring the
server closely when it runs out of steam and the timeout values are reasonable, right?