Most MariaDB performance guides tell you to "tune your configuration" without explaining what actually breaks in production. Here's what kills performance and the specific fixes that work.
InnoDB Buffer Pool: Give It Most of Your RAM
The InnoDB buffer pool is where MariaDB caches your data and indexes. If it's too small, you'll be hitting disk constantly. If it's too big, you'll run out of memory for the OS and other processes. This is the single most important setting for MariaDB performance.
The Math That Actually Works:
- Dedicated database server: Set to 70-80% of total RAM
- Shared server: Set to 50-60% of RAM
- Minimum viable: 1GB (but seriously, get more RAM)
## For a 16GB dedicated server
innodb_buffer_pool_size = 12G
## For a 8GB shared server
innodb_buffer_pool_size = 4G
Don't guess - calculate based on your actual workload. I've seen too many servers die because someone set this to 90% and left no memory for the OS. The Releem performance tuning guide has detailed calculations for different server configurations.
Query Cache: Probably Turn It Off
Query cache sounds great in theory - cache query results for faster responses. In practice, it becomes a bottleneck with high concurrency. Every INSERT, UPDATE, or DELETE invalidates related cached queries, causing cache thrashing.
## For most workloads
query_cache_type = 0
query_cache_size = 0
## Only enable if you have mostly SELECT workloads
query_cache_type = 1
query_cache_size = 128M
Modern applications with proper caching layers (Redis, Memcached) make query cache redundant. Disable it unless you have a specific read-heavy use case. Percona's performance blog covers this in detail with actual benchmarks.
Connection Management: Stop the Memory Leak
MariaDB allocates memory per connection. With default settings, you can easily hit memory limits under load.
## Don't set this higher than you need
max_connections = 200
## Reuse threads instead of creating new ones
thread_cache_size = 16
## Connection timeout to prevent hanging connections
wait_timeout = 600
interactive_timeout = 600
Connection Pool Math: Each connection uses roughly 256KB + (sort_buffer_size + read_buffer_size + join_buffer_size). With 500 connections, that's easily 1GB+ just in connection overhead. NameHero's tuning guide has detailed memory calculations for connection planning.
Log File Sizing: Stop the Checkpoint Hell
InnoDB log files control transaction logging. Too small and you get frequent checkpoints that stall writes. Too large and crash recovery takes forever.
## For write-heavy workloads
innodb_log_file_size = 1G
## Multiple log files for better I/O distribution
innodb_log_files_in_group = 2
## Log buffer to reduce disk I/O
innodb_log_buffer_size = 64M
Rule of thumb: Size your log files to handle at least an hour of peak write activity. Monitor Innodb_os_log_written
to see your actual log write rate. MariaDB's workload optimization blog explains log sizing calculations in detail.
Table Cache: Stop Opening/Closing Files
MariaDB caches open table handles to avoid filesystem overhead. Too low and you'll see constant file open/close operations.
## Base on number of tables and concurrent connections
table_open_cache = 4000
table_definition_cache = 2000
## Monitor open file limits
open_files_limit = 65535
Check your actual usage with SHOW GLOBAL STATUS LIKE 'Open%tables'
. If Opened_tables
keeps increasing rapidly, you need a larger cache. Severalnines' MariaDB tuning guide covers table caching in production environments.
The Storage Engine Trap
Stop using MyISAM unless you know exactly why you need it. InnoDB handles crash recovery, foreign keys, and row-level locking properly.
InnoDB Tuning That Matters:
## Use modern flush method
innodb_flush_method = O_DIRECT
## Separate logs from data files
innodb_log_group_home_dir = /var/log/mysql/
innodb_data_home_dir = /var/lib/mysql/
## Faster commits with some durability risk
innodb_flush_log_at_trx_commit = 2
## More I/O threads for better parallelism
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_flush_log_at_trx_commit = 2
trades some crash safety for performance. You'll survive server crashes but not system crashes. For most applications, this is fine. Releem's InnoDB tuning guide explains the durability vs performance trade-offs in detail.
Memory-Based Tables: The Temporary Table Problem
Temporary tables that exceed memory limits get written to disk, which kills performance for complex queries.
## Size for in-memory temporary tables
tmp_table_size = 256M
max_heap_table_size = 256M
## Buffer for sorting operations
sort_buffer_size = 2M
join_buffer_size = 2M
Monitor Created_tmp_disk_tables
vs Created_tmp_tables
. If more than 25% of temp tables hit disk, increase these values. Cloudways' MariaDB performance guide covers temporary table optimization with real-world examples.