SQL Error when using occ dc:add-missing-indices

Nextcloud version (eg, 12.0.2): 31.0.7
Operating system and version (eg, Ubuntu 17.04): Ubuntu 22.04.5
Apache or nginx version (eg, Apache 2.4.25): nginx
PHP version (eg, 7.1): 8.2.29

The issue you are facing:
After upgrading to Nextcloud 31.0.7 I am getting the following message when I make the occ occ dc:add-missing-indices.

I got the following errors. Did anybody know what I can do?

Error:

In ExceptionConverter.php line 42:

An exception occurred while executing a query: SQLSTATE[HY000]: General err

or: 1205 Lock wait timeout exceeded; try restarting transaction

In Exception.php line 24:

SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restar

ting transaction

In Connection.php line 33:

SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restar

ting transaction

Try to put the server into maintenance mode first. This way, there should not be any new database queries from the normal Nextcloud usage. During the procedure, NC is probably already put into maintenance mode, but perhaps there a still a few queries running and locking tables.

If nothing else uses the database, and it is just with these maintenance commands (and a db restart didn’t help), check the timeouts. Perhaps adjusting the lock wait timeouts a bit could help. If it is already quite long, there might be a different issue with your database?

I recommend to use the correct syntax.

“dc” is wrong, must be “db” (for “database”).