This issue occurred when first installing Moodle 3.9 during deployment from GitHub Actions.
TASK [Copy fresh database 3.9] *************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: DETAIL: There is 1 other session using the database.
fatal: [***]: FAILED! => {"changed": false, "msg": "Database query failed: source database \"moodle-39\" is being accessed by other users\nDETAIL: There is 1 other session using the database.\n"}
The database cannot be copied while it is being accessed. This is probably due to the cron, which means the site has to be placed in maintenance mode before preparing for reset and disabled again afterwards. This also applies to the moodle_reset playbook.