Glad it helped! ![]()
Timestamp-based cleanup
Your approach is correct — timestamp in oc_activity stores a Unix timestamp as an integer, so the comparison works exactly as you expect. That said, apply the same batching principle to avoid long-running locks:
DELETE FROM oc_activity
WHERE timestamp < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 90 DAY))
LIMIT 10000;
Repeat until 0 rows affected, then run OPTIMIZE TABLE in maintenance mode as before.
Reducing activity_expire_days to 90
Yes, this is exactly what the setting is for. Add it to your config.php:
'activity_expire_days' => 90,
The Activity app’s background job will then automatically delete entries older than 90 days on each run, so the table stays manageable going forward. 90 days is a reasonable value for a production instance — you still get meaningful history without accumulating years of log data. See the Activity configuration documentation for all available options.
Old file versions
For file version history (Files Versions app), you can clean up with:
sudo -u www-data php occ versions:cleanup
The retention behaviour can also be configured in config.php via 'versions_retention_obligation' — see the documentation for the available options.
Old calendar entries
Calendar objects (past appointments, etc.) live in oc_calendarobjects and are regular user data — Nextcloud does not automatically expire them, and there is no built-in occ command to bulk-delete old events. If you want to prune old appointments, that would need to be done at the CalDAV client level or carefully via SQL, and I would not recommend doing that without a solid backup in place first.
For backing up calendar and address book data as standard ICS/VCF files (which can be selectively re-imported afterwards), I can highly recommend the calcardbackup script by @Bernie_O — a well-maintained bash script specifically written for Nextcloud.
General database tuning
Since you mention the installation is quite old, it may be worth running MySQLTuner against your database. I use it regularly to find weak spots in MySQL configuration — buffer sizes, query cache, and other parameters. The project is still actively maintained and continues to receive contributions, which means its recommendations stay current.
h.t.h.
ernolf