Nextcloud AIO: melding “Database missing indices”

Probleem

In het Nextcloud Administration Center kreeg ik onder Security & setup warnings de volgende melding te zien:

Database missing indices

Detected some missing optional indices. Occasionally new indices are added
(by Nextcloud or installed applications) to improve database performance.
Use the command `occ db:add-missing-indices` to add them.

Missing indices:
- "mail_msg_thrd_root_snt_idx" in table "mail_messages"
- "mail_recip_eml_type_mid_idx" in table "mail_recipients"

Het ging om een Nextcloud AIO-installatie. De ontbrekende indexen leken bij de tabellen van de Nextcloud Mail-app te horen.

Omgeving

Installatietype: Nextcloud AIO
Nextcloud-container: nextcloud-aio-nextcloud
Database-container: nextcloud-aio-database
Mail-app geïnstalleerd: ja

Wat ik wilde oplossen

Ik wilde de waarschuwing uit het Administration Center oplossen zonder handmatig in PostgreSQL tabellen te gaan aanpassen.

Nextcloud geeft zelf aan dat dit via occ db:add-missing-indices kan, maar bij AIO moet je dat commando wel in de juiste container uitvoeren.

De oplossing staat in de reactie hieronder.

Oplossing

Bij Nextcloud AIO kon ik de melding oplossen door de ontbrekende database-indexen toe te voegen via occ.

Vanaf de host heb ik eerst een dry-run uitgevoerd:

sudo docker exec --user www-data -it nextcloud-aio-nextcloud php occ db:add-missing-indices --dry-run

Dit gaf de volgende output:

Adding additional mail_msg_thrd_root_snt_idx index to the oc_mail_messages table, this can take some time...
oc_mail_messages table updated successfully.
Adding additional mail_recip_eml_type_mid_idx index to the oc_mail_recipients table, this can take some time...
Removing mail_recipient_email_idx index from the oc_mail_recipients table
oc_mail_recipients table updated successfully.
DROP INDEX mail_recipient_email_idx;

CREATE INDEX mail_recip_eml_type_mid_idx ON oc_mail_recipients (email, type, message_id);

CREATE INDEX mail_msg_thrd_root_snt_idx ON oc_mail_messages (mailbox_id, thread_root_id, sent_at);

Omdat de dry-run er goed uitzag, heb ik daarna het commando echt uitgevoerd:

sudo docker exec --user www-data -it nextcloud-aio-nextcloud php occ db:add-missing-indices

Output:

Adding additional mail_msg_thrd_root_snt_idx index to the oc_mail_messages table, this can take some time...
oc_mail_messages table updated successfully.
Adding additional mail_recip_eml_type_mid_idx index to the oc_mail_recipients table, this can take some time...
Removing mail_recipient_email_idx index from the oc_mail_recipients table
oc_mail_recipients table updated successfully.

Daarna was de melding Database missing indices verdwenen uit het Nextcloud Administration Center.

Log controleren

Ik heb daarna ook nog de Nextcloud-log gecontroleerd:

sudo docker exec --user www-data -it nextcloud-aio-nextcloud sh -lc '
LOG="$(php occ config:system:get datadirectory)/nextcloud.log"
echo "Logbestand: $LOG"
tail -n 200 "$LOG"
'

In mijn geval stonden daar geen nieuwe relevante errors meer in.

Let op bij Nextcloud AIO

Bij Nextcloud AIO heet de Nextcloud-container meestal:

nextcloud-aio-nextcloud

De database-container heette in mijn installatie:

nextcloud-aio-database

Dus niet:

nextcloud-aio-postgresql

PostgreSQL-logs kun je bijvoorbeeld zo bekijken:

sudo docker logs --since=24h nextcloud-aio-database 2>&1 | tail -n 200

Conclusie

De melding was opgelost met:

sudo docker exec --user www-data -it nextcloud-aio-nextcloud php occ db:add-missing-indices

Na het uitvoeren van dit commando verdween de waarschuwing uit het Administration Center.