### What happened?
Since Matomo 5 we're seeing 3-6 times per day below fatal er…rors. We're currently on 5.0.0-rc9. This did not happen in Matomo 4 or only very rarely. There must have been some change.
## Stack trace 1
> > Error: {"message":"SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction","file":"\/libs\/Zend\/Db\/Statement\/Pdo.php","line":236,"backtrace":" on \/libs\/Zend\/Db\/Statement\/Pdo.php(236)\n#0 \/libs\/Zend\/Db\/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)\n#1 \/libs\/Zend\/Db\/Adapter\/Abstract.php(479): Zend_Db_Statement->execute(Array)\n#2 \/libs\/Zend\/Db\/Adapter\/Pdo\/Abstract.php(238): Zend_Db_Adapter_Abstract->query('UPDATE archive_...', Array)\n#3 \/core\/Db\/Adapter\/Pdo\/Mysql.php(332): Zend_Db_Adapter_Pdo_Abstract->query('UPDATE archive_...', Array)\n#4 \/core\/Db.php(281): Piwik\\Db\\Adapter\\Pdo\\Mysql->query('UPDATE archive_...', Array)\n#5 \/core\/DataAccess\/Model.php(340): Piwik\\Db::query('UPDATE archive_...', Array)\n#6 \/core\/Archive\/ArchiveInvalidator.php(701): Piwik\\DataAccess\\Model->updateRangeArchiveAsInvalidated('archive_numeric...', Array, Array, Object(Piwik\\Segment))\n#7 \/core\/Archive\/ArchiveInvalidator.php(328): Piwik\\Archive\\ArchiveInvalidator->markArchivesInvalidated(Array, Array, Object(Piwik\\Segment), true, false, NULL)\n#8 \/plugins\/CoreAdminHome\/API.php(175): Piwik\\Archive\\ArchiveInvalidator->markArchivesAsInvalidated(Array, Array, 'day', Object(Piwik\\Segment), false, false)\n#9 \/core\/CronArchive.php(982): Piwik\\Plugins\\CoreAdminHome\\API->invalidateArchivedReports(Array, Array, 'day', Object(Piwik\\Segment), false, false)\n#10 \/core\/CronArchive.php(908): Piwik\\CronArchive->invalidateWithSegments(Array, '2023-12-31', 'day', false, false)\n#11 \/core\/CronArchive.php(858): Piwik\\CronArchive->invalidateRecentDate('today', '12')\n#12 \/core\/CronArchive.php(812): Piwik\\CronArchive->invalidateArchivedReportsForSitesThatNeedToBeArchivedAgainImpl('12')\n#13 \/core\/Tracker\/Cache.php(296): Piwik\\CronArchive->Piwik\\{closure}()\n#14 \/core\/CronArchive.php(813): Piwik\\Tracker\\Cache::withDelegatedCacheClears(Object(Closure))\n#15 \/core\/CronArchive\/QueueConsumer.php(178): Piwik\\CronArchive->invalidateArchivedReportsForSitesThatNeedToBeArchivedAgain('12')\n#16 \/core\/CronArchive.php(390): Piwik\\CronArchive\\QueueConsumer->getNextArchivesToProcess()\n#17 \/core\/CronArchive.php(276): Piwik\\CronArchive->run()\n#18 \/core\/Access.php(661): Piwik\\CronArchive->Piwik\\{closure}()\n#19 \/core\/CronArchive.php(282): Piwik\\Access::doAsSuperUser(Object(Closure))\n#20 \/plugins\/CoreConsole\/Commands\/CoreArchiver.php(32): Piwik\\CronArchive->main()\n#21 \/core\/Plugin\/ConsoleCommand.php(110): Piwik\\Plugins\\CoreConsole\\Commands\\CoreArchiver->doExecute()\n#22 \/vendor\/symfony\/console\/Command\/Command.php(298): Piwik\\Plugin\\ConsoleCommand->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#23 \/core\/Plugin\/ConsoleCommand.php(125): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#24 \/vendor\/symfony\/console\/Application.php(1040): Piwik\\Plugin\\ConsoleCommand->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#25 \/vendor\/symfony\/console\/Application.php(301): Symfony\\Component\\Console\\Application->doRunCommand(Object(Piwik\\Plugins\\CoreConsole\\Commands\\CoreArchiver), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#26 \/core\/Console.php(106): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#27 [internal function]: Piwik\\Console->originDoRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#28 \/core\/Console.php(145): call_user_func(Array, Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#29 \/core\/Access.php(670): Piwik\\Console->Piwik\\{closure}()\n#30 \/core\/Console.php(146): Piwik\\Access::doAsSuperUser(Object(Closure))\n#31 \/core\/Console.php(85): Piwik\\Console->doRunImpl(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#32 \/vendor\/symfony\/console\/Application.php(171): Piwik\\Console->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#33 \/console(32): Symfony\\Component\\Console\\Application->run()\n#34 {main}\ncaused by: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction on \/libs\/Zend\/Db\/Statement\/Pdo.php(233)\n#0 \/libs\/Zend\/Db\/Statement\/Pdo.php(233): PDOStatement->execute()\n#1 \/libs\/Zend\/Db\/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)\n#2 \/libs\/Zend\/Db\/Adapter\/Abstract.php(479): Zend_Db_Statement->execute(Array)\n#3 \/libs\/Zend\/Db\/Adapter\/Pdo\/Abstract.php(238): Zend_Db_Adapter_Abstract->query('UPDATE archive_...', Array)\n#4 \/core\/Db\/Adapter\/Pdo\/Mysql.php(332): Zend_Db_Adapter_Pdo_Abstract->query('UPDATE archive_...', Array)\n#5 \/core\/Db.php(281): Piwik\\Db\\Adapter\\Pdo\\Mysql->query('UPDATE archive_...', Array)\n#6 \/core\/DataAccess\/Model.php(340): Piwik\\Db::query('UPDATE archive_...', Array)\n#7 \/core\/Archive\/ArchiveInvalidator.php(701): Piwik\\DataAccess\\Model->updateRangeArchiveAsInvalidated('archive_numeric...', Array, Array, Object(Piwik\\Segment))\n#8 \/core\/Archive\/ArchiveInvalidator.php(328): Piwik\\Archive\\ArchiveInvalidator->markArchivesInvalidated(Array, Array, Object(Piwik\\Segment), true, false, NULL)\n#9 \/plugins\/CoreAdminHome\/API.php(175): Piwik\\Archive\\ArchiveInvalidator->markArchivesAsInvalidated(Array, Array, 'day', Object(Piwik\\Segment), false, false)\n#10 \/core\/CronArchive.php(982): Piwik\\Plugins\\CoreAdminHome\\API->invalidateArchivedReports(Array, Array, 'day', Object(Piwik\\Segment), false, false)\n#11 \/core\/CronArchive.php(908): Piwik\\CronArchive->invalidateWithSegments(Array, '2023-12-31', 'day', false, false)\n#12 \/core\/CronArchive.php(858): Piwik\\CronArchive->invalidateRecentDate('today', '12')\n#13 \/core\/CronArchive.php(812): Piwik\\CronArchive->invalidateArchivedReportsForSitesThatNeedToBeArchivedAgainImpl('12')\n#14 \/core\/Tracker\/Cache.php(296): Piwik\\CronArchive->Piwik\\{closure}()\n#15 \/core\/CronArchive.php(813): Piwik\\Tracker\\Cache::withDelegatedCacheClears(Object(Closure))\n#16 \/core\/CronArchive\/QueueConsumer.php(178): Piwik\\CronArchive->invalidateArchivedReportsForSitesThatNeedToBeArchivedAgain('12')\n#17 \/core\/CronArchive.php(390): Piwik\\CronArchive\\QueueConsumer->getNextArchivesToProcess()\n#18 \/core\/CronArchive.php(276): Piwik\\CronArchive->run()\n#19 \/core\/Access.php(661): Piwik\\CronArchive->Piwik\\{closure}()\n#20 \/core\/CronArchive.php(282): Piwik\\Access::doAsSuperUser(Object(Closure))\n#21 \/plugins\/CoreConsole\/Commands\/CoreArchiver.php(32): Piwik\\CronArchive->main()\n#22 \/core\/Plugin\/ConsoleCommand.php(110): Piwik\\Plugins\\CoreConsole\\Commands\\CoreArchiver->doExecute()\n#23 \/vendor\/symfony\/console\/Command\/Command.php(298): Piwik\\Plugin\\ConsoleComman
## Stack trace 2
> [2023-12-31 01:58:08] piwik.ERROR: Scheduler: Error SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction for task 'Piwik\Plugins\CoreAdminHome\Tasks.purgeInvalidatedArchives' {"errorMessage":"SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction","task":"Piwik\\Plugins\\CoreAdminHome\\Tasks.purgeInvalidatedArchives"} {"class":"CoreAdminHome","request_id":"29337"}
### What should happen?
No fatal error
### How can this be reproduced?
Unsure.
Executed command for stack trace 1 was:
> SERVER ARGV: ["\/var\/www\/html\/console", "core:archive","--disable-scheduled-tasks","--force-idsites=12","--force-periods=week,month,year","--force-date-range=2023-01-01,2023-01-01"]
Which seems to be triggered by GA Importer. Unsure if there was maybe any change in GA importer that this is being triggered more often? I don't know why GA Importer executes this command.
Executed command for stack trace 2 was:
> console core:archive --concurrent-requests-per-website=1 --skip-segments-today --concurrent-archivers=4 --no-ansi
### Matomo version
5.0
### PHP version
_No response_
### Server operating system
_No response_
### What browsers are you seeing the problem on?
_No response_
### Computer operating system
_No response_
### Relevant log output
_No response_
### Validations
- [X] Read our [Contributing Guidelines](https://github.com/matomo-org/matomo/blob/5.x-dev/CONTRIBUTING.md).
- [X] Follow our [Security Policy](https://github.com/matomo-org/matomo/blob/5.x-dev/SECURITY.md).
- [X] Check that there isn't already an issue that reports the same bug to avoid creating duplicates.
- [X] The provided steps to reproduce is a [minimal reproducible](https://stackoverflow.com/help/minimal-reproducible-example) of the Bug.