After a Nextcloud upgrade, the admin overview likes to tell you the database is missing some indices. I run Nextcloud on my Unraid server, and this is one of those warnings I’d fix straight away instead of learning to ignore it, because missing indices mean slower queries on tables that only grow.
Upgrades don’t always add new indices to big tables themselves, so Nextcloud leaves that to you. The command adds every index the schema defines that your database doesn’t have yet. With the official nextcloud image you run occ as the www-data user inside the container; change nextcloud to the name in your Docker tab:
docker exec -it --user www-data nextcloud php occ db:add-missing-indices
Want to see what it would do first? --dry-run prints the SQL statements without running them:
docker exec -it --user www-data nextcloud php occ db:add-missing-indices --dry-run
When it’s done, reload the admin overview and the warning should be gone. Two related commands live next to it in the docs, db:add-missing-columns and db:add-missing-primary-keys, and the admin overview tells you when you need those too. On a bare-metal install it’s sudo -E -u www-data php occ db:add-missing-indices from the Nextcloud folder.
The caveat: run it as www-data, not as root, or you risk files in the data folder that the web server can’t touch afterwards. And on a big instance, adding an index to a large table takes time and keeps the database busy while it works, so I’d run it at a quiet moment and make sure there’s a recent database backup first.
Further reading: Nextcloud admin manual: database occ commands, Nextcloud Docker image: using occ
Going deeper: Guide: put Nextcloud behind Nginx Proxy Manager with HTTPS and the right headers