Database partially error Table 'nextcloud.oc_file_locks' doesn't exist

Nextcloud version (eg, 20.0.5): 16.0.9.
Operating system and version (eg, Ubuntu 20.04): TrueNAS-12.0-RELEASE
PHP: 7.1.33
DB: mysql 5.6.45

The issue you are facing:

I would like copy data from my server but there is any error. I can log, I can copy soma small files, but a lot of files cant.

An exception occurred while executing 'INSERT INTO oc_file_locks (key, lock, ttl) VALUES(?, ?, ?)' with params ["files\/70e3b39bfe3a240a56239f155f086ff8", 1, 1618696849]: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nextcloud.oc_file_locks' doesn't exist

Is this the first time you’ve seen this error? (Y/N):Y

 # occ files:scan --all
The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php
Starting scan for user 1 out of 2 (admin)
Exception during scan: An exception occurred while executing 'INSERT INTO `oc_file_locks` (`key`, `lock`, `ttl`) VALUES(?, ?, ?)' with params ["files\/e8482945c9011a1fad7f0293d9760c26", -1, 1618697519]:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nextcloud.oc_file_locks' doesn't exist
#0 /usr/local/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(184): Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))
#1 /usr/local/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(158): Doctrine\DBAL\DBALException::wrapException(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'An exception oc...')
#2 /usr/local/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(1088): Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'INSERT INTO `oc...', Array)
#3 /usr/local/www/nextcloud/lib/private/DB/Connection.php(216): Doctrine\DBAL\Connection->executeUpdate('INSERT INTO `oc...', Array, Array)
#4 /usr/local/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php(222): OC\DB\Connection->executeUpdate('INSERT INTO `oc...', Array, Array)
#5 /usr/local/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(214): Doctrine\DBAL\Query\QueryBuilder->execute()
#6 /usr/local/www/nextcloud/lib/private/DB/Adapter.php(140): OC\DB\QueryBuilder\QueryBuilder->execute()
#7 /usr/local/www/nextcloud/lib/private/DB/Connection.php(261): OC\DB\Adapter->insertIgnoreConflict('file_locks', Array)
#8 /usr/local/www/nextcloud/lib/private/Lock/DBLockingProvider.php(139): OC\DB\Connection->insertIgnoreConflict('file_locks', Array)
#9 /usr/local/www/nextcloud/lib/private/Lock/DBLockingProvider.php(200): OC\Lock\DBLockingProvider->initLockField('files/e8482945c...', -1)
#10 /usr/local/www/nextcloud/lib/private/Files/Storage/Common.php(743): OC\Lock\DBLockingProvider->acquireLock('files/e8482945c...', 2)
#11 /usr/local/www/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php(593): OC\Files\Storage\Common->acquireLock('scanner::', 2, Object(OC\Lock\DBLockingProvider))
#12 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(331): OC\Files\Storage\Wrapper\Wrapper->acquireLock('scanner::', 2, Object(OC\Lock\DBLockingProvider))
#13 /usr/local/www/nextcloud/lib/private/Files/Utils/Scanner.php(245): OC\Files\Cache\Scanner->scan('', true, 3)
#14 /usr/local/www/nextcloud/apps/files/lib/Command/Scan.php(145): OC\Files\Utils\Scanner->scan('/admin', true, NULL)
#15 /usr/local/www/nextcloud/apps/files/lib/Command/Scan.php(201): OCA\Files\Command\Scan->scanFiles('admin', '/admin', Object(Symfony\Component\Console\Output\ConsoleOutput), false, true, false)
#16 /usr/local/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OCA\Files\Command\Scan->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /usr/local/www/nextcloud/core/Command/Base.php(166): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(901): OC\Core\Command\Base->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(262): Symfony\Component\Console\Application->doRunCommand(Object(OCA\Files\Command\Scan), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(145): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /usr/local/www/nextcloud/lib/private/Console/Application.php(213): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /usr/local/www/nextcloud/console.php(97): OC\Console\Application->run()
#23 /usr/local/www/nextcloud/occ(11): require_once('/usr/local/www/...')

First check if the table exists in your database. If not, you should try to run the following occ commands to fix/repair your installation:

maintenance:repair          repair this installation

db:add-missing-indices      Add missing indices to the database tables
db:add-missing-columns      Add missing optional columns to the database tables
db:add-missing-primary-keys Add missing primary keys to the database tables.

If you still run into that error, try to create the table manually and re-run the above commands.

> describe oc_file_locks;
+-------+---------------------+------+-----+---------+----------------+
| Field | Type                | Null | Key | Default | Extra          |
+-------+---------------------+------+-----+---------+----------------+
| id    | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
| lock  | int(11)             | NO   |     | 0       |                |
| key   | varchar(64)         | NO   | UNI | NULL    |                |
| ttl   | int(11)             | NO   | MUL | -1      |                |
+-------+---------------------+------+-----+---------+----------------+
1 Like

OK, I checked
# mysqlcheck -c -u root -p --all-databases

and result

nextcloud.oc_file_locks
Error : Table ‘nextcloud.oc_file_locks’ doesn’t exist
status : Operation failed
mysqlcheck: Got error: 2013: Lost connection to MySQL server during query when executing 'CHECK TABLE … ’

after
use nextcloud;
show tables;


| oc_federated_reshares |
| oc_file_locks |
| oc_filecache |

desc oc_file_locks;

I get answer

mysql> desc oc_file_locks;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
Connection id: 1
Current database: nextcloud

ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (61)
ERROR:
Can’t connect to the server

In this case you definitely have a problem with your database server. You should investigate further why the server connection get lost or the database becomes unresponsive.

https://duckduckgo.com/?t=ffab&q=truenas+MySQL+server+has+gone+away&ia=web

OK, I have solution for my problem. I downloaded WinSCP, loged in to my server and found path to my data. /mnt/nashome/iocage/jails/nextcloud/root/usr/local/www/nextcloud/data/admin/files/ and download. After that reinstal nextcloud.

1 Like