What the message looks like
The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically.Common causes
- Update to a new major version that brings new indexes.
- Indexes were never added after earlier updates.
- Migration from SQLite or a manual database import without the full schema.
Check
- Show missing indexes without changing anything
sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices --dry-run - Show missing columns and primary keys
sudo -u www-data php /var/www/nextcloud/occ db:add-missing-columns --dry-run; sudo -u www-data php /var/www/nextcloud/occ db:add-missing-primary-keys --dry-run - Find the largest tables to estimate duration
mysql -e "SELECT table_name, ROUND((data_length+index_length)/1024/1024) AS mb FROM information_schema.tables WHERE table_schema='nextcloud' ORDER BY mb DESC LIMIT 5;"
Fix
- Take a database backup first.
- On large instances enable maintenance mode:
occ maintenance:mode --on. - Add indexes:
occ db:add-missing-indices, thenocc db:add-missing-columnsandocc db:add-missing-primary-keys. - If reported, also run
occ db:convert-filecache-bigint. - Disable maintenance mode and reload the admin overview.
Typical scenario
After moving to the next major version, the overview under Administration shows the warning 'The database is missing some indexes'. The instance has 3 million files and the oc_filecache table is correspondingly large. Nextcloud does not create such indexes itself because that can take a long time on big tables. So schedule occ db:add-missing-indices for a quiet window and take a database backup first.
FAQ
How long does it take?
Seconds on small instances. On an oc_filecache with many millions of rows it can take minutes to hours and lock the table meanwhile.
Can I just ignore the message?
Nextcloud keeps running, but file lists, shares and search get noticeably slower as data grows. It is worth doing.
Is creating the indexes risky?
It changes only the structure, not the data, but on large tables it can take minutes to hours and put load on the database. During live operation, requests may slow down. So run it outside peak load and with a current backup.
Why does the warning sometimes persist after the command?
The overview caches check results briefly. There are also related commands for other structural problems, such as occ db:add-missing-columns and occ db:add-missing-primary-keys. The message tells you which type of problem exists.
What do missing indexes actually cause?
Queries have to scan whole tables instead of accessing rows directly. That makes file lists, search and background jobs noticeably slower, particularly with many files. After creating them, database load often drops considerably.