@Alain ...
Strange ...
IF you were to backup the course you are trying to copy via command line does it complete?
Other courses might be smaller or not use same modules as the troubled course.
Anything in that course that's 'heavy processing' - like course has 10,000 users and there multiple quizzes/test?
Then there's the totality of what's going on at the time of your copy ... which includes cron jobs and task. From your description sounds like it's sporadic ... you can copy sometimes but not at others. If there a cleanup task that's romping on course copy?
On a temp basis, you could copy the DB user and DB password lines in config.php and use 'superuser' creds on the new lines - commenting out the old lines to see if this is a priv issue with the original DB user.
Also, what flavor or DB engine running? Version of DB engine? MySQL? Have you recently upgraded MySQL?
8 is now using TLS for communications if DB server is dedicated - had trouble with an upgrade from 5.7 to 8.0 MySQL because of that and had to tweak my.cnf settings to mimic the old behavior. On a new server with MySQL 8 installed already had no such issue.
If I re-call, you are running true RHEL and can't upgrade to higher versions of Moodle due to lack of php extensions not provided by RHEL - you can't use 3rd party repos.
What's the 'blessed' DB engine by RH now-a-days - and version?
'SoS', Ken
by Ken Task.