Database going wild on Nextcloud, eating 30% CPU continuously, 3bn reads per monh

Support intro

Nextcloud version: (30.0.2)
Operating system and version: Unraid 6.12.13
Database: Maria DB 11.5.2

I’m running Nextcloud on a homeserver with 16 GB RAM and a 4 TB NVMe disk on Unraid. My family (four people) are the only users and besides some synchronisation of photos taken on the mobile devices, Nextcloud most of the time just sits there without much to do.

Nevertheless I noted, that the home server is pretty hot and one of the CPUs is always at 30%. Looking more closely I found, the there are per month about 3 billion read operations and 8 million write operations on the NVMe per month.

Playing around I noticed, that the usage of CPU and read/write operations stops, when I stop the Nextcloud container.
So I started a bin log of the MariaDB database.

Result: Nextloud is sending A LOT of statements to the database, even if nobody is logged into Nextcloud.

Any ideas how I can calm down Nextcloud?

Here’s a snippet of the stuff that is repeating again and again (all the time):

START TRANSACTION
/*!*/;
# Annotate_rows:
#Q> UPDATE `oc_appconfig` SET `configvalue` = '160', `lazy` = 0, `type` = 2 WHERE (`appid` = 'backgroundjob') AND (`configkey` = 'lastjob')
COMMIT/*!*/;
START TRANSACTION
/*!*/;
# Annotate_rows:
#Q> UPDATE `oc_jobs` SET `reserved_at` = '1731344701', `last_checked` = '1731344701' WHERE (`id` = '161') AND (`reserved_at` = '0') AND (`last_checked` = '1731344401')
COMMIT/*!*/;
START TRANSACTION
/*!*/;
# Annotate_rows:
#Q> UPDATE `oc_jobs` SET `last_run` = 1731344701 WHERE `id` = 161
COMMIT/*!*/;
START TRANSACTION
/*!*/;
# Annotate_rows:
#Q> UPDATE `oc_jobs` SET `execution_duration` = 0, `reserved_at` = 0 WHERE `id` = 161
COMMIT/*!*/;
START TRANSACTION
/*!*/;
# Annotate_rows:
#Q> UPDATE `oc_appconfig` SET `configvalue` = '161', `lazy` = 0, `type` = 2 WHERE (`appid` = 'backgroundjob') AND (`configkey` = 'lastjob')
COMMIT/*!*/;
START TRANSACTION
/*!*/;
# Annotate_rows:
#Q> UPDATE `oc_jobs` SET `reserved_at` = '1731344701', `last_checked` = '1731344701' WHERE (`id` = '162') AND (`reserved_at` = '0') AND (`last_checked` = '1731344401')
COMMIT/*!*/;
START TRANSACTION
/*!*/;
# Annotate_rows:
#Q> UPDATE `oc_jobs` SET `last_run` = 1731344701 WHERE `id` = 162
COMMIT/*!*/;
START TRANSACTION
/*!*/;
# Annotate_rows:
#Q> UPDATE `oc_jobs` SET `execution_duration` = 0, `reserved_at` = 0 WHERE `id` = 162
COMMIT/*!*/;
START TRANSACTION
/*!*/;
# Annotate_rows:
#Q> UPDATE `oc_appconfig` SET `configvalue` = '162', `lazy` = 0, `type` = 2 WHERE (`appid` = 'backgroundjob') AND (`configkey` = 'lastjob')
COMMIT/*!*/;
  • Tell us which image specifically you’re using (there are many including third-party ones)
  • Post your config (occ config:list system)
  • Tell us which apps you have installed (occ app:list)

You might also consider adjusting your logging within Nextcloud itself (loglevel) temporarily to get a bit better idea of what jobs are running and what they’re doing.

Database: Maria DB 11.5.2

Lastly, note that Nextcloud Server isn’t spec’d for MariaDB 11.5.x, which is a short-term release. Only LTS releases are officially supported[1][2]. I’m not saying this is the the cause of your issues, but it is relevant to mention given the context.

Logs seems for me ok. Logs from every 5 minutes cron job. Post more details e.g. config.php. Some ideas. Search first the internet for the effects.

Set maintenance in the night:
'maintenance_window_start' => 1,

Set activity to 30 days
'activity_expire_days' => 30,

Maybe missing indices:
sudo -u www-data php occ db:add-missing-indices

If the CPU load really comes from mariadb and is outside the 5 minute cron jobs, try to find out more about the MariaDB. Logs of the MariaDB, connections, CPU consumption, memory consumption, …

If Nextcloud is not used and the 5 minutes are not reached, Nextcloud should not perform any database queries at all, as no PHP programme accesses the database.

The container I’m using is of linuxserver (lscr.io/linuxserver/nextcloud:latest).

Output of occ config:list system - the sensitive value is removed by the system.

{
    "system": {
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "192.168.178.56:1443"
        ],
        "dbtype": "mysql",
        "version": "30.0.2.2",
        "overwrite.cli.url": "https:\/\/192.168.178.56:1443",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "memcache.local": "\\OC\\Memcache\\APCu",
        "filelocking.enabled": true,
        "memcache.locking": "\\OC\\Memcache\\APCu",
        "upgrade.disable-web": true,
        "maintenance_window_start": 1,
        "loglevel": 2,
        "maintenance": false,
        "app_install_overwrite": [
            "onlyoffice",
            "libresign",
            "workflow_media_converter"
        ]
    }
}

And here is the list of apps. I would be deligted, if the prob could be solved with the remoal of an app.

Enabled:
  - activity: 3.0.0
  - admin_audit: 1.20.0
  - app_api: 4.0.0
  - bruteforcesettings: 3.0.0
  - calendar: 5.0.1
  - circles: 30.0.0
  - cloud_federation_api: 1.13.0
  - comments: 1.20.1
  - contacts: 6.1.0
  - contactsinteraction: 1.11.0
  - dav: 1.31.1
  - deck: 1.14.1
  - federatedfilesharing: 1.20.0
  - federation: 1.20.0
  - files: 2.2.0
  - files_downloadlimit: 3.0.0
  - files_pdfviewer: 3.0.0
  - files_reminders: 1.3.0
  - files_sharing: 1.22.0
  - files_trashbin: 1.20.1
  - files_versions: 1.23.0
  - firstrunwizard: 3.0.0
  - forms: 4.3.2
  - logreader: 3.0.0
  - lookup_server_connector: 1.18.0
  - nextcloud_announcements: 2.0.0
  - notes: 4.11.0
  - notifications: 3.0.0
  - oauth2: 1.18.1
  - password_policy: 2.0.0
  - photos: 3.0.2
  - privacy: 2.0.0
  - provisioning_api: 1.20.0
  - recommendations: 3.0.0
  - related_resources: 1.5.0
  - serverinfo: 2.0.0
  - settings: 1.13.0
  - sharebymail: 1.20.0
  - support: 2.0.0
  - survey_client: 2.0.0
  - suspicious_login: 8.0.0
  - systemtags: 1.20.0
  - text: 4.1.0
  - theming: 2.5.0
  - twofactor_backupcodes: 1.19.0
  - updatenotification: 1.20.0
  - user_status: 1.10.0
  - viewer: 3.0.0
  - webhook_listeners: 1.1.0-dev
  - workflowengine: 2.12.0
Disabled:
  - dashboard: 7.10.0 (installed 7.10.0)
  - encryption: 2.18.0 (installed 2.18.0)
  - files_external: 1.22.0
  - richdocuments: 8.4.3 (installed 8.4.3)
  - spreed: 19.0.6 (installed 19.0.6)
  - twofactor_nextcloud_notification: 4.0.0 (installed 4.0.0)
  - twofactor_totp: 12.0.0-dev (installed 12.0.0-dev)
  - user_ldap: 1.21.0 (installed 1.21.0)
  - weather_status: 1.10.0 (installed 1.10.0)

Thanks a lot!

Thanks for your hints and ideas.

Logs seems for me ok. Logs from every 5 minutes cron job.

Well, these log entries re-occur every few seconds, not minutes. I checked the longer version of binlog: the statements get repeated seeral times a second - then there is a pause of 20 to 25 seconds an it starts off again…

Here’s my config.php

$CONFIG = array (
  'datadirectory' => '/data',
  'instanceid' => 'ocmnmmancfwt',
  'passwordsalt' => [...] ,
  'secret' => [...],
  'trusted_domains' => 
  array (
    0 => '192.168.178.56:1443',
  ),
  'dbtype' => 'mysql',
  'version' => '30.0.2.2',
  'overwrite.cli.url' => 'https://192.168.178.56:1443',
  'dbname' => 'nextcloud',
  'dbhost' => '192.168.178.56:3306',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'oc_nx-admin',
  'dbpassword' => [...],
  'installed' => true,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\APCu',
  'upgrade.disable-web' => true,
  'maintenance_window_start' => 1,
  'loglevel' => 2,
  'maintenance' => false,
  'app_install_overwrite' => 
  array (
    0 => 'onlyoffice',
    1 => 'libresign',
    2 => 'workflow_media_converter',
  ),
);

I’ll try your other tips on the weekend.

cheers and thanks!