The “the database is slow” ticket is usually one of two problems wearing the same disguise: MariaDB configured for the wrong workload size, or a server that’s genuinely out of capacity. Throwing hardware at the first wastes money; tuning the second wastes the weekend. The diagnostic order matters.
The trade-off
Tuning is cheap and reversible. Hardware upgrades are expensive and partially reversible. Always tune first — but only after measuring, not by copy-pasting my.cnf snippets from a 2014 blog post written for a different MariaDB version on different hardware.
How to verify — the diagnostic order
- Look at the slow query log first. Enable it if it’s not on:
slow_query_log=1,long_query_time=2,log_queries_not_using_indexes=1. Run for 24 hours of normal traffic. One missing index on one busy table is usually the entire problem. - Check
SHOW ENGINE INNODB STATUS\Gfor buffer pool hit ratio, wait events, and lock contention. Buffer pool hit ratio under 99% on a working set that should fit in RAM = under-sizedinnodb_buffer_pool_size. - Look at
mysqltuner.ploutput. Not gospel, but it flags obvious misconfigurations — buffer pool sized to default 128MB on a 64GB box, max connections set to 1000 with no thread pool, MyISAM tables when everything should be InnoDB. - Check disk I/O against database load.
iostat -x 5while traffic is real. If %util on the data disk is sustained above 80%, you’re disk-bound — tune harder or move to faster storage. - Check per-account query patterns. WHM > Manage MySQL Profiles. One account running
SELECT * FROM wp_optionswithoutautoloadindexed is a different problem from “we need more RAM”.
What to do
In order, stopping when the problem goes away:
- Add the missing indexes the slow query log identified.
- Set
innodb_buffer_pool_sizeto roughly 50-70% of dedicated database RAM (less if MySQL shares the box with PHP-FPM and other tenants). - Set
innodb_log_file_sizeto roughly 25% of buffer pool, capped at 4GB. - Set
innodb_flush_method=O_DIRECTon Linux with direct I/O — avoids double-buffering between MariaDB and the OS. - Confirm
query_cache_type=OFFon MariaDB 10.6+ — the query cache is a known contention point at any concurrency. - If buffer pool hit ratio is still under 99% with the working set fully cached, you actually do need more RAM. Add iron.
- If queries are well-indexed and the buffer pool is large enough but disk wait dominates, you actually do need faster disk. Move to NVMe.
For dense shared hosting, also consider splitting MariaDB to a dedicated database host. Stack Harbor handles this diagnostic order as part of WHM server management.