MariaDB Performance Tuning
Guide

A Comprehensive Guide to MariaDB Performance Tuning
DEC 9, 2024 • WRITTEN BY ROMAN AGABEKOV
MariaDB is a major player in the open-source database world, originally developed as a fork of MySQL. It's known for its reliability and feature-rich environment powering countless applications with efficiency and speed. rich set of features that make it a go-to choice for many applications. To keep your MariaDB server running at its best, fine-tuning is essential. In this guide, we'll cover practical tips to optimize your setup, like adjusting configuration settings, using effective indexing strategies, and monitoring performance metrics.

1. Start with Documentation

To effectively tune MariaDB, it's important that you get familiar with its detailed documentation. This will help you better understand configuration settings and how they impact MariaDB’s performance. Check out these resources to learn more:

2. Study Best Practices for MariaDB Configuration

Not all settings have a profound impact on performance. But for those few key variables that do, you want to learn how to configure them properly according to your specific workload requiremnts and available hardware.

The following resources cover a wide range of topics, including important variables, how connections impact performance, and InnoDB optimization help:

3. Setup Monitoring (If Not Already in Place)

When you are comfortable with MariaDB documentation and configuration best practices, you can turn to your monitoring data as a source of valuable information on your servers health. Monitoring tools allow you to monitor key performance metrics and figure out where improvements can be made.

  • Zabbix is an open-source tool for monitoring networks, servers, cloud environments, applications, and services. It's highly secure and scalable.
  • Prometheus is an open-source monitoring software known for its simplicity and powerful visualization tools.
  • Percona Monitoring and Management focuses on improving database performance and data security, offering useful insights and tools for DBAs.
  • Releem is perfect for monitoring MySQL and MariaDB databases. Releem offers a user-friendly solution with automatic configuration recommendations to improve performance and query optimization assistance.
Metrics to Watch & What to Look Out For
1. CPU Usage
Keeping tabs on CPU usage reveals how much processing power your MariaDB server is using. If you notice consistently high CPU usage, it might mean your server is handling a heavy load or there's room for improving your queries and configuration. You could also upgrade your hardware.
2. Memory Usage
Watching memory usage gives you insight into how much RAM your MariaDB server is consuming. If memory usage is nearing its limit, performance can take a hit. Seeing swap usage means your system is compensating with disk space, a clear sign that more RAM might be needed.
3. Disk I/O
Disk I/O metrics show how quickly data is read from and written to the disk. High disk I/O can slow things down, especially for large databases or heavy transaction volumes. If you see high read/write latency, your storage might be lagging behind, while high throughput suggests frequent large data transfers.
4. Connections
Tracking active connections helps you manage your MariaDB server's load. A high number of connections can lead to resource contention, which may slow down your server. Connection errors could indicate configuration problems or that the server is reaching its resource limits.
5. Error Rates
Error rates are useful for spotting and fixing issues with your MariaDB server, like failed queries or connection problems. A sudden spike in errors can signal deeper issues that need immediate attention, while recurring specific errors might point to configuration or coding problems that need to be addressed.

4. Analyze Your MariaDB Server Status

Before you can start making performance optimizations your server needs to be running for a minimum of 24 hours. At that point, there’s enough data to check the status of server variables.
Run the following command to pull up various performance metrics and look for outliers that could benefit from some tweaking.
SHOW GLOBAL STATUS; 
With Releem, you can easily monitor 19 important metrics with health checks across the 3 categories listed below – cache performance metrics, database efficiency metrics, and temporary data metrics:
Metrics for Cache Performance
By analyzing hit rates and fragmentation for specific cache types—such as thread, table, MyISAM, and InnoDB—you can uncover bottlenecks and optimization opportunities. Tracking these metrics allows you to fine-tune your caching strategy, guaranteeing rapid data access and optimal cache utilization. Key metrics include:

Metrics for Database Efficiency
By examining write ratios, you can understand the balance between data writes and reads, which sheds light on your database's ability to handle modifications. Monitoring log file sizes helps you detect inefficiencies in data logging and storage, as rapid growth might signal underlying issues. Sort merge passes reveal the efficiency of data sorting operations – a higher count may indicate the need for better memory management or indexing. Key metrics include:

Metrics for Temporary Data
Monitoring the creation and management of temporary data during operations highlights inefficiencies in query execution or storage systems. For example, high levels of Temporary Disk Data – the amount written to disk during queries – can signal the need for configuration tweaks to better manage this data.

5. Get Configuration Recommendations from Scripts

Since MariaDB is a fork of MySQL, it shares a very similar architecture. This means most scripts that work for MySQL also work with MariaDB. The following tools can be used to extract configuration recommendations by analyzing your current configuration and metrics:

  • MySQLTuner – This Perl script offers performance suggestions and identifies potential security issues.
  • Tuning-Primer Script – This script provides recommendations based on "SHOW STATUS LIKE..." and "SHOW VARIABLES LIKE..." commands. Though the original is no longer maintained, a fully supported version for MariaDB is available on GitHub.
  • Percona Toolkit – A suite of open-source command-line tools that simplify database management, allowing you to focus on more strategic tasks.
  • Mysqlreport – Converts SHOW STATUS data into a user-friendly report, giving a clear snapshot of your database performance. From MariaDB 10.4.6 onward, mysqlreport is linked to mariadb-report, and from 10.5.2, mysqlreport is the primary tool.

6. Calculate Values of MariaDB Performance Settings

At the core of MariaDB tuning is the calculation of the best values for various performance parameters. This process can be time-consuming and complex. With Releem, DBAs can avoid all the associated manual work of these calculations. Releem automates the tuning process from start to finish, handling the optimizing for you. All you have to do is apply the recommended configuration.

7. SQL Query Optimization

Optimizing SQL queries is also critical for overall MariaDB performance. Inefficient queries can lead to high resource usage and slow response times.
EXPLAIN Statements
MariaDB offers a helpful tool called the EXPLAIN statement, which reveals exactly how your queries are processed It provides a step-by-step breakdown, showing which parts of the query are most resource-intensive. This helps you determine if your queries are efficient or could use some work.
Using The Slow Query Log
The Slow Query Log records queries that exceed a specified duration to execute. For example, if you set the long_query_time to 2 seconds, the log will contain all queries that take more than 2 seconds to complete.

To start using the Slow Query Log, you need to enable it. Edit your my.cnf or my.ini file to add the following:
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-queries.log
long_query_time = 2
Focus on the queries that appear most often in the log since they likely affect performance the most. Pay attention to execution times to see which queries are the slowest. Also, review the number of rows processed to gauge how much they are taxing your database resources.
Try Query Analytics & Optimization from Releem
While the Slow Query Log helps in identifying slow queries, Releem’s Query Analytics and Query optimization features goes further by providing a comprehensive view of your MariaDB server's query performance and actionable insights. It automatically detects inefficient queries that consume excessive resources, such as CPU, memory, and disk I/O and suggest recommendations to improve them. The Query Analytics feature ranks your top queries based on execution time and total load, offering detailed insights into which queries need optimization.

With real-time monitoring and an intuitive interface, Releem simplifies the process of query optimization, saving you valuable time and effort by allowing you to quickly identify and address performance issues.

8. Create a New Configuration File

After reviewing your database's performance and deciding which variables need changes, it's time to set up a new configuration file with these adjustments:

  1. Create a backup of your existing configuration file. This acts as a safeguard if you need to revert to the original settings.
  2. Open the configuration file (my.cnf) in a text editor.
  3. Modify the configuration settings based on your performance needs, manual calculations, or recommendations from tools like Releem.
  4. Save the updated configuration file with the .cnf extension in the appropriate directory so that MariaDB can access and apply the changes.

9. Apply the New Configuration File

After preparing your new configuration file, you need to restart the MariaDB server to activate the changes:

  • On Linux, use the following command
sudo systemctl restart mariadb.
  • On Windows, open the Services management console (services.msc), find MariaDB or MySQL, right-click it, and select Restart.

Releem Does All This And More

Releem simplifies the often complex and time-consuming process of MariaDB optimization for database administrators. Instead of manually sifting through performance metrics and configuration settings, Releem automatically analyzes your server workload, database usage patterns, and overall system health. It pinpoints specific areas where performance is lagging, such as inefficient queries or suboptimal configuration settings.
WRITTEN BY ROMAN AGABEKOV
Ready to dive in?
Try Releem today for FREE! No credit card required.