Our matomo_log_action table has grown to a whopping 240 million records and 140+ GB. None of the settings to shrink the database have done anything for this table, neither have the tasks “Piwik\Plugins\PrivacyManager\Tasks.deleteReportData” and “Piwik\Plugins\PrivacyManager\Tasks.deleteLogData” or the suggestions from https://matomo.org/faq/on-premise/managing-your-databases-size/ and https://matomo.org/faq/how-to/faq_20184/. The table keeps growing and growing, making updates and backups harder and harder. I was only able to reduce the size of matomo_log_visit and matomo_log_link_visit_action, but not of matomo_log_action.
The description of “console core:delete-logs-data” states “Delete data from the user log tables: log_visit, log_link_visit_action, log_conversion, log_conversion_item, log_action.”, but that does not seem to be true for the last table. Running this command does not reduce the number of records in log_action.
Is there any way to reduce the size of this table?
A table that big usually means you are storing a huge number of distinct URLs, not that the purge is broken. The log_action cleanup only removes rows that no remaining visit or link action points to, so with a long retention window most rows are still referenced and nothing goes. I’d check what is filling it first. Group by type and look at a sample of the newest rows. Very often it is tracking URLs with session IDs, timestamps or search parameters that make every page view a new row. If so, add those parameters to the excluded URL parameters in the website settings, consider shorter log retention, then run the delete logs command again so orphaned rows can be cleared. Take a full backup first, and optimize the table afterward since disk space will not shrink on its own.
I understand, but the sheer size of the table makes it hard to work with. I can run simple SQL statements, but anything involving grouping or sorting makes the server crash or lose connection.
Theoretically, if I would truncate the table (after a backup, of course) and start fresh, what exactly would I lose? The ability to create more reports with custom date ranges, transitions, etc.?
After that, I could also reimport all the logfiles (we don’t use JS tracking) of the last 6 months and refill the log tables to get some of the data back, but this could take weeks…
Careful with TRUNCATE: it resets AUTO_INCREMENT, so new actions would reuse old idaction values and any raw rows you keep in log_visit / log_link_visit_action would point to the wrong URLs.
Reports already archived in archive_* tables should survive, but Transitions and any re-archiving (invalidations, new segments) read raw logs (verify for your version).
Safer: profile it in small chunks, e.g. `SELECT type, COUNT(*) FROM matomo_log_action WHERE idaction BETWEEN 1 AND 5000000 GROUP BY type`, add the noisy URL params to exclusions, shorten raw retention, rerun delete-logs-data, then OPTIMIZE (needs free disk).
For heavier GROUP BYs, use a replica. Disclosure: I co-founded dbtrail (open source), which keeps a queryable Parquet copy of MySQL tables for this kind of analysis.
This sounds like an issue with orphaned action records. I’d check Matomo’s database cleanup options and ask support whether log_action requires a separate cleanup process.
If you go the truncate route, don’t truncate only log_action. Old rows in log_visit/log_link_visit_action still contain idaction references, and after AUTO_INCREMENT resets those IDs can point at unrelated new actions. For a true fresh start, clear the raw log tables together (after backup), keep the archive_* reports, then reimport. You’ll lose re-archiving, segments and transitions over old raw data, but archived reports should remain. Test on a copy first.
Before you truncate anything, check whether the newest rows are mostly one noisy parameter, since a single session id in every URL can bloat this table fast.
Once those parameters are excluded, shorten the raw log retention and run the delete logs command again, then check the orphaned rows are actually gone before you touch the table by hand.
Grouping on the whole table is too heavy, so maybe just look at the newest slice, like rows with an idaction above the max id minus a million. If a few URL patterns repeat there (session IDs or search params), you will see it fast and can exclude them in the site settings.