After update to 20.0.2 occ db:add-missing-primary-keys

After updating today to 20.0.2 I get the Security & setup warnings in /settings/admin/overview

here are some warnings regarding your setup.

  • The database is missing some primary keys. Due to the fact that adding primary keys on big tables could take some time they were not added automatically. By running “occ db:add-missing-primary-keys” those missing primary keys could be added manually while the instance keeps running.
    • Missing primary key on table “oc_federated_reshares”.
    • Missing primary key on table “oc_systemtag_object_mapping”.
    • Missing primary key on table “oc_comments_read_markers”.
    • Missing primary key on table “oc_collres_resources”.
    • Missing primary key on table “oc_collres_accesscache”.
    • Missing primary key on table “oc_filecache_extended”.

I’m running Nextcloud on a Pine64 Rockpro together with OpenMediaVault 5 (NGINX / Debian based).
Nextcloud 20.0.1 was running without any warmings or security issues

This is normal behaviour: As stated in the message the command might take some time and therefore isn’t run automatically. Just run the command “occ db:add-missing-primary-keys” from the command line (occ is located in the Nextcloud root directory).

If you don’t have access to the command line, you could also try to install the app “occweb” and run it from within the app.

thx, need some extra help

NAS-rockpro64:/var/www/nextcloud$ ls
3rdparty config core index.php ocm-provider public.php robots.txt updater
apps console.php cron.php lib ocs remote.php status.php version.php
AUTHORS COPYING index.html occ ocs-provider resources themes
hemertje@NAS-rockpro64:/var/www/nextcloud$

NAS-rockpro64:/var/www/nextcloud$ occ db:add-missing-primary-keys

Command ‘occ’ not found, did you mean:

command ‘gcc’ from deb gcc
command ‘gcc’ from deb pentium-builder
command ‘ocp’ from deb opencubicplayer
command ‘kcc’ from deb kcc
command ‘hcc’ from deb lam4-dev
command ‘orcc’ from deb liborc-0.4-dev-bin
command ‘fcc’ from deb fcc
command ‘ncc’ from deb tinyos-tools
command ‘bcc’ from deb bcc
command ‘osc’ from deb osc
command ‘ocs’ from deb cscope
command ‘tcc’ from deb tcc
command ‘rcc’ from deb qtchooser

Try: sudo apt install

occ is in this directorie but not found?

Try ./occ db:add-missing-primary-keys :wink:

yes did that

root@NAS-rockpro64:/var/www/nextcloud# ./occ db:add-missing-primary-keys
-bash: ./occ: Permission denied
root@NAS-rockp:/var/www/nextcloud#

From the Apps: OCC Web 0.0.7

This app cannot be installed because the following dependencies are not fulfilled:

  • Server version 18 or lower is required.

Here you find further infos about occ and how to use:

2 Likes

thx for pointing me

hemertje@NAS-rockpro64:/var/www/nextcloud$ sudo -u www-data php occ db:add-missing-primary-keys
Check primary keys.
Adding primary key to the federated_reshares table, this can take some time…
federated_reshares table updated successfully.
Adding primary key to the systemtag_object_mapping table, this can take some time…
systemtag_object_mapping table updated successfully.
Adding primary key to the comments_read_markers table, this can take some time…
comments_read_markers table updated successfully.
Adding primary key to the collres_resources table, this can take some time…
collres_resources table updated successfully.
Adding primary key to the collres_accesscache table, this can take some time…
collres_accesscache table updated successfully.
Adding primary key to the filecache_extended table, this can take some time…
filecache_extended table updated successfully.
hemertje@NAS-rockpro64:/var/www/nextcloud$

6 Likes

Thanks a lot, running the command “sudo -u www-data php occ db:add-missing-primary-keys” inside /var/www/nextcloud got the same output as posted and once refreshed the Overview page in Nextcloud got that sweet sweet All checks passed. :white_check_mark:

2 Likes

occ db:add-missing-primary-keys

is this command new since NC 20? My 19.0.x says, this “command is not defined”.

Is it nescessary in any case to run this directly after upgrading from 19 to 20 to make the upgraded NC install working well?

Good morning,
I have the same problem as this topic but I have a snap installation on my Ubuntu 20.04 server.
That is why a solution mentioned above does not work for me.
My installation path is:

tony@nxtc:/var/snap/nextcloud$ ll
total 20
drwxr-xr-x 5 root root 4096 Dec  2 05:05 ./
drwxr-xr-x 6 root root 4096 Nov 11 07:33 ../
drwxr-xr-x 8 root root 4096 Nov 12 00:00 24051/
drwxr-xr-x 8 root root 4096 Nov 12 00:00 24739/
drwxr-xr-x 3 root root 4096 Nov 11 07:34 common/
lrwxrwxrwx 1 root root    5 Dec  2 05:05 current -> 24739/
tony@nxtc:/var/snap/nextcloud$ 

Can you somebody help me what commands and where be needed to run?

Because when I tried

tony@nxtc:/var/snap/nextcloud$ sudo -u www-data php occ db:add-missing-primary-keys
sudo: php: command not found

Thank you for your answer.

So I found and use this solution. It is for SNAP installation.

  1. Download and enable app OCCweb.
  2. Run this command
    db:add-missing-primary-keys

It worked for me and all missing keys were added successfully.
Source of solution here.

https://github.com/nextcloud/nextcloud-snap#included-cli-utilities explains how to run occ for snap. No need to install occweb.

good evening, I have a problem when I type this order sudo -u www-data php occ db: add-missing-primary-keys this shows me Segmentation fault (core dumped) if you can help me.

Dear comunity! I thank you very much. I always find useful help with you when I’m looking for something here, thank you very much for this

regards !

So I found and use this solution from vawaver community member !

  1. Download and enable app OCCweb.
  2. Run this command
    db:add-missing-primary-keys

It worked for me and all missing keys were added successfully.
Source of solution here.

Keep in mind that OCC web is no longer supported and abandoned by the developer.

That’s right, for security reasons! But it still works very well. There is no better alternative without it all taking far too long to fix the errors.

The best way would be to run the occ commands directly on your server. But many shared hosters don’t support that.

If you can access your DB via e.g. phpMyAdmin you could try to run the commands manually.