My site is slow because of the database: what to do

Category: Web hosting

If your monthly report says your database has slow queries or that it hit the server’s usage limit, some pages on your site take long because they wait for the database. While a slow query runs, that visit takes one of your plan’s slots for simultaneous visits. If several overlap, the whole site slows down or shows an error for a few seconds.

A slow query is almost never a server problem. It comes from something your site does: a plugin, a report or a table that grew out of control. These are the most common causes and what you can do.

In WordPress

Plugins that query too much. The usual suspects are visit statistics, advanced search, “related posts”, activity logs and form builders that store every submission. To find the culprit:

  1. Install the Query Monitor plugin (free), open the slowest page and check in the top bar which plugin runs the slowest queries.
  2. Deactivate that plugin and test again. If the site improves, look for a lighter alternative or review its settings.
  3. When you’re done, deactivate Query Monitor; it uses resources too.

Tables that grew out of control. Post revisions, spam comments, expired “transients” and logs from plugins that store everything. The guide to speed up WordPress explains what to clean without breaking anything. Then optimize the tables in phpMyAdmin.

Stores with many products. In WooCommerce, turn on high-performance order storage in WooCommerce → Settings → Advanced → Features. It moves orders to their own tables and speeds up the dashboard.

Object cache. If your plan includes Redis, turn it on: it keeps repeated queries in memory and the database stops receiving them.

In Moodle

In Moodle, slow queries almost always come from the logs, reports and the gradebooks of large courses.

  • Limit how long you keep logs. In Site administration → Plugins → Logging → Standard log, set Keep logs for to a period such as 365 days instead of Never delete logs. It’s the table that grows the most in any Moodle.
  • Schedule heavy reports outside class hours. If teachers pull full-course activity reports mid-morning, let them know it overlaps with exams.
  • Check that cron runs. If it doesn’t, cleanup tasks pile up and then run all at once. See how to check Moodle’s cron.

When to ask us for help

You can’t see the exact slow query from cPanel, but we can. If you already went through the above and the warning stays, open a ticket: we’ll tell you which table and query it is, and which plugin or section of your site it comes from.

If your site simply grew (more products, more students, more simultaneous visits), you may need more resources. Check in Resource Usage whether you hit your plan’s limits before moving to a bigger plan.

Still need help?

If this guide didn’t solve your issue, our team can help you via ticket.