Nextcloud database table corrupt > how to repair?

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 28.0.2
Operating system and version (eg, Ubuntu 20.04): ubuntu 22.04
Apache or nginx version (eg, Apache 2.4.25): nginx
PHP version (eg, 7.4): 8.2.16

The issue you are facing:

`An exception occurred while executing a query: SQLSTATE[HY000]: 
General error: 1034 Index for table 'oc_systemtag_object_mapping' is 
corrupt; try to repair it`

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

Steps to replicate it:

  1. I do not know what happened and caused the problem. Most probably it happened when watchtower updated the docker container.

The output of your Nextcloud log in Admin > Logging:

{"reqId":"CI7TMf1IAbApwVocYCF0","level":3,"time":"2024-02-24T17:19:52+00:00","remoteAddr":"","user":"--","app":"core","method":"","url":"--","message":"Error while running background job (class: OCA\\Recognize\\BackgroundJobs\\ClassifyLandmarksJob, arguments: Array\n(\n    [storageId] => 10\n    [rootId] => 2092500\n)\n)","userAgent":"--","version":"28.0.2.5","exception":{"Exception":"Doctrine\\DBAL\\Exception\\DriverException","Message":"An exception occurred while executing a query: SQLSTATE[HY000]: General error: 1034 Index for table 'oc_systemtag_object_mapping' is corrupt; try to repair it","Code":1034,"Trace":[{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":1938,"function":"convert","class":"Doctrine\\DBAL\\Driver\\API\\MySQL\\ExceptionConverter","type":"->","args":[["Doctrine\\DBAL\\Driver\\PDO\\Exception"],["Doctrine\\DBAL\\Query"]]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":1880,"function":"handleDriverException","class":"Doctrine\\DBAL\\Connection","type":"->","args":[["Doctrine\\DBAL\\Driver\\PDO\\Exception"],["Doctrine\\DBAL\\Query"]]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":1208,"function":"convertExceptionDuringQuery","class":"Doctrine\\DBAL\\Connection","type":"->","args":[["Doctrine\\DBAL\\Driver\\PDO\\Exception"],"INSERT INTO `oc_systemtag_object_mapping` (`objectid`, `objecttype`, `systemtagid`) VALUES(?, ?, ?)",["2476515","files","173"],[2,2]]},{"file":"/var/www/html/lib/private/DB/Connection.php","line":294,"function":"executeStatement","class":"Doctrine\\DBAL\\Connection","type":"->","args":["INSERT INTO `oc_systemtag_object_mapping` (`objectid`, `objecttype`, `systemtagid`) VALUES(?, ?, ?)",["2476515","files","173"],[2,2]]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php","line":386,"function":"executeStatement","class":"OC\\DB\\Connection","type":"->","args":["INSERT INTO `oc_systemtag_object_mapping` (`objectid`, `objecttype`, `systemtagid`) VALUES(:dcValue1, :dcValue2, :tagid)",["2476515","files","173"],[2,2]]},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":280,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/SystemTag/SystemTagObjectMapper.php","line":149,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/apps/recognize/lib/Service/TagManager.php","line":77,"function":"assignTags","class":"OC\\SystemTag\\SystemTagObjectMapper","type":"->","args":["2476515","files",["101","173","1",8,9]]},{"file":"/var/www/html/apps/recognize/lib/Classifiers/Images/LandmarksClassifier.php","line":47,"function":"assignTags","class":"OCA\\Recognize\\Service\\TagManager","type":"->","args":[2476515,["101","173","1"]]},{"file":"/var/www/html/apps/recognize/lib/BackgroundJobs/ClassifyLandmarksJob.php","line":41,"function":"classify","class":"OCA\\Recognize\\Classifiers\\Images\\LandmarksClassifier","type":"->","args":[[["OCA\\Recognize\\Db\\QueueFile",6762],["OCA\\Recognize\\Db\\QueueFile",6763],["OCA\\Recognize\\Db\\QueueFile",6764],["OCA\\Recognize\\Db\\QueueFile",6765],["OCA\\Recognize\\Db\\QueueFile",6766],["OCA\\Recognize\\Db\\QueueFile",6767],["OCA\\Recognize\\Db\\QueueFile",6768],["OCA\\Recognize\\Db\\QueueFile",6769],["OCA\\Recognize\\Db\\QueueFile",6770],["OCA\\Recognize\\Db\\QueueFile",6771],["OCA\\Recognize\\Db\\QueueFile",6772],["OCA\\Recognize\\Db\\QueueFile",6773],["OCA\\Recognize\\Db\\QueueFile",6774],["OCA\\Recognize\\Db\\QueueFile",6775],["OCA\\Recognize\\Db\\QueueFile",6776],["OCA\\Recognize\\Db\\QueueFile",6777],["OCA\\Recognize\\Db\\QueueFile",6778],["OCA\\Recognize\\Db\\QueueFile",6779],["OCA\\Recognize\\Db\\QueueFile",6780],["OCA\\Recognize\\Db\\QueueFile",6781]]]},{"file":"/var/www/html/apps/recognize/lib/BackgroundJobs/ClassifierJob.php","line":73,"function":"classify","class":"OCA\\Recognize\\BackgroundJobs\\ClassifyLandmarksJob","type":"->","args":[[["OCA\\Recognize\\Db\\QueueFile",6762],["OCA\\Recognize\\Db\\QueueFile",6763],["OCA\\Recognize\\Db\\QueueFile",6764],["OCA\\Recognize\\Db\\QueueFile",6765],["OCA\\Recognize\\Db\\QueueFile",6766],["OCA\\Recognize\\Db\\QueueFile",6767],["OCA\\Recognize\\Db\\QueueFile",6768],["OCA\\Recognize\\Db\\QueueFile",6769],["OCA\\Recognize\\Db\\QueueFile",6770],["OCA\\Recognize\\Db\\QueueFile",6771],["OCA\\Recognize\\Db\\QueueFile",6772],["OCA\\Recognize\\Db\\QueueFile",6773],["OCA\\Recognize\\Db\\QueueFile",6774],["OCA\\Recognize\\Db\\QueueFile",6775],["OCA\\Recognize\\Db\\QueueFile",6776],["OCA\\Recognize\\Db\\QueueFile",6777],["OCA\\Recognize\\Db\\QueueFile",6778],["OCA\\Recognize\\Db\\QueueFile",6779],["OCA\\Recognize\\Db\\QueueFile",6780],["OCA\\Recognize\\Db\\QueueFile",6781]]]},{"file":"/var/www/html/apps/recognize/lib/BackgroundJobs/ClassifyLandmarksJob.php","line":33,"function":"runClassifier","class":"OCA\\Recognize\\BackgroundJobs\\ClassifierJob","type":"->","args":["landmarks",[10,2092500]]},{"file":"/var/www/html/lib/public/BackgroundJob/Job.php","line":81,"function":"run","class":"OCA\\Recognize\\BackgroundJobs\\ClassifyLandmarksJob","type":"->","args":[[10,2092500]]},{"file":"/var/www/html/lib/public/BackgroundJob/TimedJob.php","line":102,"function":"start","class":"OCP\\BackgroundJob\\Job","type":"->","args":[["OC\\BackgroundJob\\JobList"]]},{"file":"/var/www/html/lib/public/BackgroundJob/TimedJob.php","line":92,"function":"start","class":"OCP\\BackgroundJob\\TimedJob","type":"->","args":[["OC\\BackgroundJob\\JobList"]]},{"file":"/var/www/html/cron.php","line":152,"function":"execute","class":"OCP\\BackgroundJob\\TimedJob","type":"->","args":[["OC\\BackgroundJob\\JobList"],["OC\\Log"]]}],"File":"/var/www/html/3rdparty/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php","Line":117,"Previous":{"Exception":"Doctrine\\DBAL\\Driver\\PDO\\Exception","Message":"SQLSTATE[HY000]: General error: 1034 Index for table 'oc_systemtag_object_mapping' is corrupt; try to repair it","Code":1034,"Trace":[{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php","line":132,"function":"new","class":"Doctrine\\DBAL\\Driver\\PDO\\Exception","type":"::","args":[["PDOException",["HY000",1034,"Index for table 'oc_systemtag_object_mapping' is corrupt; try to repair it"]]]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":1202,"function":"execute","class":"Doctrine\\DBAL\\Driver\\PDO\\Statement","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/Connection.php","line":294,"function":"executeStatement","class":"Doctrine\\DBAL\\Connection","type":"->","args":["INSERT INTO `oc_systemtag_object_mapping` (`objectid`, `objecttype`, `systemtagid`) VALUES(?, ?, ?)",["2476515","files","173"],[2,2]]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php","line":386,"function":"executeStatement","class":"OC\\DB\\Connection","type":"->","args":["INSERT INTO `oc_systemtag_object_mapping` (`objectid`, `objecttype`, `systemtagid`) VALUES(:dcValue1, :dcValue2, :tagid)",["2476515","files","173"],[2,2]]},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":280,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/SystemTag/SystemTagObjectMapper.php","line":149,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/apps/recognize/lib/Service/TagManager.php","line":77,"function":"assignTags","class":"OC\\SystemTag\\SystemTagObjectMapper","type":"->","args":["2476515","files",["101","173","1",8,9]]},{"file":"/var/www/html/apps/recognize/lib/Classifiers/Images/LandmarksClassifier.php","line":47,"function":"assignTags","class":"OCA\\Recognize\\Service\\TagManager","type":"->","args":[2476515,["101","173","1"]]},{"file":"/var/www/html/apps/recognize/lib/BackgroundJobs/ClassifyLandmarksJob.php","line":41,"function":"classify","class":"OCA\\Recognize\\Classifiers\\Images\\LandmarksClassifier","type":"->","args":[[["OCA\\Recognize\\Db\\QueueFile",6762],["OCA\\Recognize\\Db\\QueueFile",6763],["OCA\\Recognize\\Db\\QueueFile",6764],["OCA\\Recognize\\Db\\QueueFile",6765],["OCA\\Recognize\\Db\\QueueFile",6766],["OCA\\Recognize\\Db\\QueueFile",6767],["OCA\\Recognize\\Db\\QueueFile",6768],["OCA\\Recognize\\Db\\QueueFile",6769],["OCA\\Recognize\\Db\\QueueFile",6770],["OCA\\Recognize\\Db\\QueueFile",6771],["OCA\\Recognize\\Db\\QueueFile",6772],["OCA\\Recognize\\Db\\QueueFile",6773],["OCA\\Recognize\\Db\\QueueFile",6774],["OCA\\Recognize\\Db\\QueueFile",6775],["OCA\\Recognize\\Db\\QueueFile",6776],["OCA\\Recognize\\Db\\QueueFile",6777],["OCA\\Recognize\\Db\\QueueFile",6778],["OCA\\Recognize\\Db\\QueueFile",6779],["OCA\\Recognize\\Db\\QueueFile",6780],["OCA\\Recognize\\Db\\QueueFile",6781]]]},{"file":"/var/www/html/apps/recognize/lib/BackgroundJobs/ClassifierJob.php","line":73,"function":"classify","class":"OCA\\Recognize\\BackgroundJobs\\ClassifyLandmarksJob","type":"->","args":[[["OCA\\Recognize\\Db\\QueueFile",6762],["OCA\\Recognize\\Db\\QueueFile",6763],["OCA\\Recognize\\Db\\QueueFile",6764],["OCA\\Recognize\\Db\\QueueFile",6765],["OCA\\Recognize\\Db\\QueueFile",6766],["OCA\\Recognize\\Db\\QueueFile",6767],["OCA\\Recognize\\Db\\QueueFile",6768],["OCA\\Recognize\\Db\\QueueFile",6769],["OCA\\Recognize\\Db\\QueueFile",6770],["OCA\\Recognize\\Db\\QueueFile",6771],["OCA\\Recognize\\Db\\QueueFile",6772],["OCA\\Recognize\\Db\\QueueFile",6773],["OCA\\Recognize\\Db\\QueueFile",6774],["OCA\\Recognize\\Db\\QueueFile",6775],["OCA\\Recognize\\Db\\QueueFile",6776],["OCA\\Recognize\\Db\\QueueFile",6777],["OCA\\Recognize\\Db\\QueueFile",6778],["OCA\\Recognize\\Db\\QueueFile",6779],["OCA\\Recognize\\Db\\QueueFile",6780],["OCA\\Recognize\\Db\\QueueFile",6781]]]},{"file":"/var/www/html/apps/recognize/lib/BackgroundJobs/ClassifyLandmarksJob.php","line":33,"function":"runClassifier","class":"OCA\\Recognize\\BackgroundJobs\\ClassifierJob","type":"->","args":["landmarks",[10,2092500]]},{"file":"/var/www/html/lib/public/BackgroundJob/Job.php","line":81,"function":"run","class":"OCA\\Recognize\\BackgroundJobs\\ClassifyLandmarksJob","type":"->","args":[[10,2092500]]},{"file":"/var/www/html/lib/public/BackgroundJob/TimedJob.php","line":102,"function":"start","class":"OCP\\BackgroundJob\\Job","type":"->","args":[["OC\\BackgroundJob\\JobList"]]},{"file":"/var/www/html/lib/public/BackgroundJob/TimedJob.php","line":92,"function":"start","class":"OCP\\BackgroundJob\\TimedJob","type":"->","args":[["OC\\BackgroundJob\\JobList"]]},{"file":"/var/www/html/cron.php","line":152,"function":"execute","class":"OCP\\BackgroundJob\\TimedJob","type":"->","args":[["OC\\BackgroundJob\\JobList"],["OC\\Log"]]}],"File":"/var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Exception.php","Line":28,"Previous":{"Exception":"PDOException","Message":"SQLSTATE[HY000]: General error: 1034 Index for table 'oc_systemtag_object_mapping' is corrupt; try to repair it","Code":"HY000","Trace":[{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php","line":130,"function":"execute","class":"PDOStatement","type":"->","args":[null]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":1202,"function":"execute","class":"Doctrine\\DBAL\\Driver\\PDO\\Statement","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/Connection.php","line":294,"function":"executeStatement","class":"Doctrine\\DBAL\\Connection","type":"->","args":["INSERT INTO `oc_systemtag_object_mapping` (`objectid`, `objecttype`, `systemtagid`) VALUES(?, ?, ?)",["2476515","files","173"],[2,2]]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php","line":386,"function":"executeStatement","class":"OC\\DB\\Connection","type":"->","args":["INSERT INTO `oc_systemtag_object_mapping` (`objectid`, `objecttype`, `systemtagid`) VALUES(:dcValue1, :dcValue2, :tagid)",["2476515","files","173"],[2,2]]},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":280,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/SystemTag/SystemTagObjectMapper.php","line":149,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/apps/recognize/lib/Service/TagManager.php","line":77,"function":"assignTags","class":"OC\\SystemTag\\SystemTagObjectMapper","type":"->","args":["2476515","files",["101","173","1",8,9]]},{"file":"/var/www/html/apps/recognize/lib/Classifiers/Images/LandmarksClassifier.php","line":47,"function":"assignTags","class":"OCA\\Recognize\\Service\\TagManager","type":"->","args":[2476515,["101","173","1"]]},{"file":"/var/www/html/apps/recognize/lib/BackgroundJobs/ClassifyLandmarksJob.php","line":41,"function":"classify","class":"OCA\\Recognize\\Classifiers\\Images\\LandmarksClassifier","type":"->","args":[[["OCA\\Recognize\\Db\\QueueFile",6762],["OCA\\Recognize\\Db\\QueueFile",6763],["OCA\\Recognize\\Db\\QueueFile",6764],["OCA\\Recognize\\Db\\QueueFile",6765],["OCA\\Recognize\\Db\\QueueFile",6766],["OCA\\Recognize\\Db\\QueueFile",6767],["OCA\\Recognize\\Db\\QueueFile",6768],["OCA\\Recognize\\Db\\QueueFile",6769],["OCA\\Recognize\\Db\\QueueFile",6770],["OCA\\Recognize\\Db\\QueueFile",6771],["OCA\\Recognize\\Db\\QueueFile",6772],["OCA\\Recognize\\Db\\QueueFile",6773],["OCA\\Recognize\\Db\\QueueFile",6774],["OCA\\Recognize\\Db\\QueueFile",6775],["OCA\\Recognize\\Db\\QueueFile",6776],["OCA\\Recognize\\Db\\QueueFile",6777],["OCA\\Recognize\\Db\\QueueFile",6778],["OCA\\Recognize\\Db\\QueueFile",6779],["OCA\\Recognize\\Db\\QueueFile",6780],["OCA\\Recognize\\Db\\QueueFile",6781]]]},{"file":"/var/www/html/apps/recognize/lib/BackgroundJobs/ClassifierJob.php","line":73,"function":"classify","class":"OCA\\Recognize\\BackgroundJobs\\ClassifyLandmarksJob","type":"->","args":[[["OCA\\Recognize\\Db\\QueueFile",6762],["OCA\\Recognize\\Db\\QueueFile",6763],["OCA\\Recognize\\Db\\QueueFile",6764],["OCA\\Recognize\\Db\\QueueFile",6765],["OCA\\Recognize\\Db\\QueueFile",6766],["OCA\\Recognize\\Db\\QueueFile",6767],["OCA\\Recognize\\Db\\QueueFile",6768],["OCA\\Recognize\\Db\\QueueFile",6769],["OCA\\Recognize\\Db\\QueueFile",6770],["OCA\\Recognize\\Db\\QueueFile",6771],["OCA\\Recognize\\Db\\QueueFile",6772],["OCA\\Recognize\\Db\\QueueFile",6773],["OCA\\Recognize\\Db\\QueueFile",6774],["OCA\\Recognize\\Db\\QueueFile",6775],["OCA\\Recognize\\Db\\QueueFile",6776],["OCA\\Recognize\\Db\\QueueFile",6777],["OCA\\Recognize\\Db\\QueueFile",6778],["OCA\\Recognize\\Db\\QueueFile",6779],["OCA\\Recognize\\Db\\QueueFile",6780],["OCA\\Recognize\\Db\\QueueFile",6781]]]},{"file":"/var/www/html/apps/recognize/lib/BackgroundJobs/ClassifyLandmarksJob.php","line":33,"function":"runClassifier","class":"OCA\\Recognize\\BackgroundJobs\\ClassifierJob","type":"->","args":["landmarks",[10,2092500]]},{"file":"/var/www/html/lib/public/BackgroundJob/Job.php","line":81,"function":"run","class":"OCA\\Recognize\\BackgroundJobs\\ClassifyLandmarksJob","type":"->","args":[[10,2092500]]},{"file":"/var/www/html/lib/public/BackgroundJob/TimedJob.php","line":102,"function":"start","class":"OCP\\BackgroundJob\\Job","type":"->","args":[["OC\\BackgroundJob\\JobList"]]},{"file":"/var/www/html/lib/public/BackgroundJob/TimedJob.php","line":92,"function":"start","class":"OCP\\BackgroundJob\\TimedJob","type":"->","args":[["OC\\BackgroundJob\\JobList"]]},{"file":"/var/www/html/cron.php","line":152,"function":"execute","class":"OCP\\BackgroundJob\\TimedJob","type":"->","args":[["OC\\BackgroundJob\\JobList"],["OC\\Log"]]}],"File":"/var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php","Line":130}},"message":"Error while running background job (class: OCA\\Recognize\\BackgroundJobs\\ClassifyLandmarksJob, arguments: Array\n(\n    [storageId] => 10\n    [rootId] => 2092500\n)\n)","exception":{},"CustomMessage":"Error while running background job (class: OCA\\Recognize\\BackgroundJobs\\ClassifyLandmarksJob, arguments: Array\n(\n    [storageId] => 10\n    [rootId] => 2092500\n)\n)"}}

Is that a MySQL/MariaDB or PostgreSQL database?


Take the values from your config/config.php:

DB_HOST = 'dbhost'
DB_USER = 'dbuser'
DB_PASS = 'dbpassword'
DB_NAME = 'dbname'


If dbtype is mysql:

Open a terminal and enter

mysql --host=$DB_HOST --user=$DB_USER --password=$DB_PASS $DB_NAME --no-auto-rehash --default-character-set=utf8mb4

Now you should be inside of the MySQL/MariaDB command line console. If your database name is “nextcloud”, It should look like this:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 210114
Server version: 10.11.7-MariaDB-1:10.11.7+maria~ubu2204-log mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [nextcloud]>

now enter this repair command at the

MariaDB [nextcloud]>

prompt:

REPAIR TABLE oc_systemtag_object_mapping;

After that is ready, you can exit the MySQL/MariaDB Console with

\q

If dbtype is pgsql:

Open a terminal and enter

PGPASSWORD=$DB_PASS psql --host=$DB_HOST --user=$DB_USER -d$DB_NAME

Now you should be inside of the PostgreSQL command line console. If your database name is “nextcloud”, It should look like this:

psql (14.10 (Ubuntu 14.10-0ubuntu0.22.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

nextcloud=>

now enter this repair commands at the

nextcloud=>

prompt:

REINDEX INDEX oc_systemtag_object_mapping_pkey;

and

REINDEX INDEX systag_by_tagid;

After that is ready, you can exit the PostgreSQL Console with

\q

I hope this will repair the database table.


Much and good luck,
ernolf

1 Like

Thanks for the answer!

I used the nextcloud repair command:
sudo -u www-data php occ maintenance:repair
and it worked well

https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html

2 Likes