Deleteing Matamo Site; also deleting all data from database?

We have a Matomo install we need to clean some websites and their data out of.

I’ve gone into the Web UI and deleted the websites there. They no longer show up in the web UI - that’s grand.

Do I need to do anything to delete the data from the database too?

I have seen https://matomo.org/docs/managing-your-databases-size/ but that’s slightly different - I don’t want to delete old/archive data from websites I am keeping. I just want to make sure that all the data for these deleted websites is gone.

I’ve had a look in the database.

I can see in the piwik_site the row is totally gone for the site, so that’s fine. say, id=27

  • select * from piwik_site where idsite =27; (0 rows)

But if I run things like:

  • select * from piwik_log_visit where siteid=27 limit 1;
  • select * from piwik_archive_numeric_2020_04 where idsite =27 limit 1;

I can see actual data still exists.

So I guess I can run things like (PSEUDO-SQL, NOT TESTED):

  • Delete from piwik_log_visit where siteid not in (select siteid from piwik_site);
  • Delete from piwik_archive_numeric_2020_04 where siteid not in (select siteid from piwik_site);

But is there no cli command or function that does this for me? It feels like I shouldn’t have to run raw SQL to do this and I’m wary of messing something else up.

Ok, this seems to have sorted itself out. The data is now gone.

I had already assumed that it wouldn’t delete straight away, but that the background worker that runs from cron would do this. So I waited a few days after deleting before checking, but it seems it needs longer than that and I’m not sure why.

But it’s done now - just took longer that I expected.