Any custom report gives error

If I try to select a date range other than today’s date, dashboard data is not loaded and it gives below error.
The same error I’m getting for Visitors -> Device if I add a new segment, no report is generated and It gives below error.

Error:
Oops… there was a problem during the request. Maybe the server had a temporary issue, or maybe you requested a report with too much data. Please try again. If this error occurs repeatedly please contact your Matomo administrator for assistance.

Please have a look at How to Set up Auto-Archiving of Your Reports - Analytics Platform - Matomo

Segments can take quite long to be calculated. It seems like your server is returning a timeout before the result was ready to be served. Setting your Segment to “preProcess” could help here.

Hi,

Thanks for your response.

I already have auto archiving in place, please refer to the below cron scheduler command that I have

5 * * * * www-data /usr/bin/php /var/www/html/piwik/console core:archive --url=http://mydomain/piwik/ > /home/user/archive/piwik-archive.log

For a day report it works, but as soon as I try to change it to week range or any other option. It gives error.