Published: 09.07.2026
A dynamic website asks its database dozens of questions for every page. When the database is slow, the whole site is slow, even if the server is powerful. The good news is that a few simple habits remove most database problems.

Find out what is slow
Do not guess. Enable the slow query log with a threshold of one second and look at the queries that appear most often or take longest. Many control panels and plugins show the same information. Fix the biggest problem first and measure again.
Use indexes correctly
An index is like the index of a book: it lets the database find rows without reading the whole table. Add indexes to columns used in WHERE conditions, joins and sorting. Do not index everything, because every index slows down writes and uses disk space. The EXPLAIN command shows whether a query uses an index.
Write lighter queries
- Select only the columns you need instead of everything.
- Avoid running a query inside a loop; fetch the data once and process it in code.
- Use limits and pagination for long lists.
- Avoid functions on indexed columns in conditions, because they prevent the index from being used.
- Prefer exact conditions to wildcard searches that start with a percent sign.
Choose the right storage engine
InnoDB is the standard engine for modern sites. It supports transactions, row-level locking and crash recovery. Old MyISAM tables lock the whole table during writes, which causes waiting on busy sites. If you still have MyISAM tables, plan their conversion and test on a copy first.
Give the database enough memory
The most important setting is the InnoDB buffer pool: the memory where data and indexes are cached. On a server dedicated mostly to the database it is often half or more of the available memory. On a shared server with a web server the share is smaller. If the database can keep its working set in memory, reads become much faster.
Clean the data
- Delete expired sessions, transients, logs and spam comments.
- Remove old post revisions or limit their number.
- Archive or delete orders and records that nobody uses.
- Remove tables left by uninstalled plugins after making a backup.
Use caching so the database is asked less
An object cache such as Redis or Memcached stores results of frequent queries in memory. A page cache avoids running the application and the database at all for anonymous visitors. These two tools usually give the largest gain for the least effort.
Maintenance tasks
- Run table checks and optimisation during quiet hours.
- Keep the database server updated to a supported version.
- Back up regularly and test a restore.
- Watch the disk space, because a full disk stops the database.
Connections and limits
Too many simultaneous connections cause errors such as "too many connections". Close connections properly in the code, use persistent connections with care and set the maximum number to a value that your memory can support. Many connections are often a symptom of slow queries that keep sessions busy.
Know when to scale
If a well-tuned database still slows down, move it to a stronger server, a separate machine or a replica for reading. Before that, check that the cause is the load and not one expensive query.
Frequently asked questions
Is there a tool that does everything automatically? Tuning scripts give hints, but only measurements on your own data show what to change.
Should I change many settings at once? No. Change one setting, measure, and keep a note of the result.
Can a plugin slow the database? Yes. Some plugins run heavy queries on every page. Disable them one by one to find the cause.