I'm facing a memory management issue with MariaDB in one of my projects. My environment:
MariaDB version: 10.6.18
Total RAM: 4GB
Current Configuration:
[mysqld]
innodb_buffer_pool_size = 256M
max_connections = 100
table_open_cache = 800
thread_cache_size = 24
query_cache_size = 0
Problem: At startup, MariaDB consumes less than 1GB of memory, which is expected. However, over time, memory usage grows beyond 2GB and eventually crashes due to an Out of Memory (OOM) kill, with this systemd error:
systemd[1]: mariadb.service: Failed with result 'oom-kill'.
Restarting the server every few days temporarily resolves the issue, but I’m looking for a more sustainable solution.
Question:
Is there a way to force MariaDB to release unused memory instead of holding onto it unnecessarily?
Are there configuration tweaks or commands that can help prevent memory leaks and excessive memory retention?
Any insights or best practices to manage MariaDB's memory efficiently would be greatly appreciated!
I'm facing a memory management issue with MariaDB in one of my projects. My environment:
MariaDB version: 10.6.18
Total RAM: 4GB
Current Configuration:
[mysqld]
innodb_buffer_pool_size = 256M
max_connections = 100
table_open_cache = 800
thread_cache_size = 24
query_cache_size = 0
Problem: At startup, MariaDB consumes less than 1GB of memory, which is expected. However, over time, memory usage grows beyond 2GB and eventually crashes due to an Out of Memory (OOM) kill, with this systemd error:
systemd[1]: mariadb.service: Failed with result 'oom-kill'.
Restarting the server every few days temporarily resolves the issue, but I’m looking for a more sustainable solution.
Question:
Is there a way to force MariaDB to release unused memory instead of holding onto it unnecessarily?
Are there configuration tweaks or commands that can help prevent memory leaks and excessive memory retention?
Any insights or best practices to manage MariaDB's memory efficiently would be greatly appreciated!
Share Improve this question edited Mar 4 at 0:08 ysth 98.6k6 gold badges125 silver badges217 bronze badges asked Mar 3 at 18:08 AFA MedAFA Med 2472 silver badges13 bronze badges 4 |1 Answer
Reset to default 2Your settings seem fine, even conservative, for 4GB of RAM, so I think the problem is elsewhere.
No, there is no way (that I know of, other than restarting) to force MySQL/MariaDB to free up memory.
Are there other applications (web server, clients, etc) running on the same server?
Although
max_connections = 100
is reasonable, I would start by cutting that in half and checking the clients (eg Apache) to see that they are not flooding MariaDB with hundreds of connections.If this is Linux (or similar OS), edit
/etc/sysctl.conf
and addvm.swappiness = 1
to the end. This should make the OS slower to hit OOM.Upgrade MariaDB. There is a tiny chance of a "memory leak" in the version you are using. (If you can narrow down what is causing the suspected leak, file a bug report.)
In case this Question gets closed, move to dba.stackexchange .
show global status like '%memory%';
might provide a comparison point. – danblack Commented Mar 4 at 2:27